<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Rafael &quot;Auyer&quot; Passos on Medium]]></title>
        <description><![CDATA[Stories by Rafael &quot;Auyer&quot; Passos on Medium]]></description>
        <link>https://medium.com/@rcpassos?source=rss-e354c9e0c053------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*4MK9vWMsftFifF0ZsLjz6w.jpeg</url>
            <title>Stories by Rafael &amp;quot;Auyer&amp;quot; Passos on Medium</title>
            <link>https://medium.com/@rcpassos?source=rss-e354c9e0c053------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 21:58:08 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@rcpassos/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Lightweight Large Data Extractions with Polars and ConnectorX]]></title>
            <link>https://medium.com/@rcpassos/lightweight-large-data-extractions-with-polars-and-connectorx-4936ea605f58?source=rss-e354c9e0c053------2</link>
            <guid isPermaLink="false">https://medium.com/p/4936ea605f58</guid>
            <category><![CDATA[rust]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[apache-arrow]]></category>
            <dc:creator><![CDATA[Rafael "Auyer" Passos]]></dc:creator>
            <pubDate>Mon, 08 May 2023 22:45:20 GMT</pubDate>
            <atom:updated>2024-01-24T13:12:50.899Z</atom:updated>
            <content:encoded><![CDATA[<h3>Lightweight ETLs For Larger Than RAM Tables With Polars And ConnectorX</h3><p>In my last blog post, I shared the latest tool that I have added to my arsenal — Apache Arrow (or the libraries based on it). In this post, I will delve deeper into the topic and demonstrate some of the techniques I employed.</p><p>If you have not read it yet, I highly suggest you do so before this one. I also shared a brief version of the journey I went through while creating the data platform that we currently use at my company : <a href="https://rcpassos.me/post/apache-arrow-future-of-data-engineering">How I Decreased ETL Cost by Leveraging the Apache Arrow Ecosystem</a>.</p><h3><strong>ConnectorX, and what it does differently</strong></h3><p>The first thing you might notice when you check ConnectorX is that it is implemented in Rust. However, this is not the only reason it is a good library. The developers evaluated the existing solutions in Python and found weaknesses in them, specifically that they involved too much data copying. Check out their awesome <a href="https://github.com/sfu-db/connector-x#citing-connectorx">paper about it</a>.</p><p>Being implemented in Rust helps a lot with resource efficiency and speed, but it is only one of its advantages. The thing the developers found about other libraries is that they take a lot of time allocating and copying data in memory. This leads to a lot of I/O and wasted CPU cycles. ConnectorX follows the “zero-copy” principle, just like Apache Arrow, where the data is copied only once, directly from the source to the destination, even when parallelism is involved.</p><p>The last key to our success is that this library can write in the Apache Arrow format. In the last post, we used Polars (and PyArrow), both of which use the Arrow memory format. With ConnectorX, we can load the output from the `<em>connectorx.read_sql`</em> function directly into Polars without any need for serialization or reallocations.</p><h3><strong>Reading with large tables</strong></h3><p>In my previous post, I demonstrated a basic script for extracting data using the libraries I mentioned earlier. This script used a simple `select * from table` query and wrote the output to a Parquet file. However, this method is only practical for handling small tables.</p><p>If you attempt to extract data from a large table in a small machine, you are likely to encounter an out-of-memory panic. This occurs because the ConnectorX library collects all the query results before passing them to Polars in the Arrow format. Thus, in order to use the same script, the dataset must be small enough to fit into memory.</p><p>One solution to this problem is vertical scaling, which involves providing additional resources such as Memory and CPU to the workload. However, this approach can be expensive and has its limitations. You should use it within a reasonable budget limit or while developing a better long-term solution.</p><h3><strong>Partitioning</strong></h3><p>The solution to handling a large dataset is to partition it into smaller pieces, which is often referred to as partitioning. This approach involves breaking down the table into more manageable pieces, which can be processed individually, thereby avoiding the challenges of dealing with the entire dataset at once.</p><p>To efficiently partition a table, you need a cursor column that you can use to sort the table. This column enables you to read the table in an organized manner. Date columns are commonly used, and some numeric values can be used for this too. However, using a sequential number is the best option as it is predictable. It allows for effortless partitioning of the dataset.</p><p>Partitioning by date may not result in uniformly-sized partitions if the table is not uniform. For instance, if there are 2k rows in October and 200k in November, the extraction will require significantly more resources for the November partition. To avoid this issue, using a sequential number as a cursor column is recommended as it ensures that each partition is of the same size, regardless of the data distribution.</p><p>In addition, it is important to index the cursor column. Queries will use a statement such as `select * from the table where cursor &gt;= ? and cursor &lt; ?`, which means the database will sort by the cursor column. Failing to index the cursor column will result in a slow and expensive table scan, which could affect the efficiency of your system. Nonetheless, before creating a new index, it is recommended to test it first to ensure that it is necessary. Creating a new column or index have their cost as well.</p><p>To implement this, you will need to decide how to partition your table. In my case, I will use a sequential numeric id and will decide the number of partitions based on the reported size that Postgres gives me.</p><pre>query_min_max = f&quot;&quot;&quot;select min({PARTITION_COLUMN}) as min_id,<br>        max({PARTITION_COLUMN}) as max_id,<br>        pg_total_relation_size(&#39;{SCHEMA}.{TABLE}&#39;) as size<br>    from {SCHEMA}.{TABLE}&quot;&quot;&quot;<br><br>df_min_max = read_sql(query_min_max, conn).to_dicts()[0]<br><br>parts = math.ceil(df_min_max[&quot;size&quot;] / 1000000000) # one GB per part</pre><p>With the values from this query, you know how many lines you have (if the table is not sequential, you can run a count query), and the first and the last values of the `PARTITION_COLUMN`.</p><p>The next part is to run your queries in a loop and processes them one part at a time.</p><pre>start = df_min_max[&quot;min_id&quot;]<br>stop = df_min_max[&quot;max_id&quot;]<br>step = math.ceil((stop - start) / parts)<br>for i in range(0, parts):<br>    df = read_sql(<br>        f&quot;&quot;&quot;select sb.* from ({query}) sb<br>        where {PARTITION_COLUMN} &gt;= {start + step * i}<br>        and {PARTITION_COLUMN} &lt; {start + step * (i + 1)}&quot;&quot;&quot;,<br>        conn,<br>    )<br>    # process your df here</pre><p>My actual implementation is a bit fancier than this though. I created a function that returns a generator. What this means, is that the result of the function will look and behave like an Iterator, but each element will be processed only when it is called by the iteration process.</p><pre>def query_generator_ranges(conn, start, stop, parts) -&gt; Iterator[pl.LazyFrame]:<br>step = math.ceil((stop - start) / parts)<br><br>query = f&quot;select * from {SCHEMA}.{TABLE}&quot;<br><br>return (<br>    (<br>        read_sql(<br>            f&quot;&quot;&quot;select sb.* from ({query}) sb<br>            where {PARTITION_COLUMN} &gt;= {start + step * i}<br>            and {PARTITION_COLUMN} &lt; {start + step * (i + 1)}&quot;&quot;&quot;,<br>            conn,<br>            ).lazy()<br>    )<br>    for i in range(0, parts)<br>)</pre><p>And I use it like this:</p><pre>dfs = query_generator_ranges(conn, start, stop, parts)<br>for df in dfs:<br>    # process your df here</pre><h3><strong>Doing Transformations in this data</strong></h3><p>I will keep this section short because it can be easier to do complex transformations later in the pipeline after we collect all the raw tables. It can also be useful to have a copy of the data in the database in your datalake. If I need to create a new dataset from aggregations, by joining two tables, I do it by scanning the datalake instead of the source.</p><p>So far our extraction return a dataframe for every part. You can write it to the destination directly, or do a bit of row-wise processing there. Just add the next bits of code to the for loop where I left a `# process your df here` comment.</p><p>One thing I usually do is add the date of extraction to the rows. This can be useful when troubleshooting later. If you have this kind of tracing, you can add ids and other metadata here. But know that every row in this table will have them. I also prefix added columns with an underscore to make them easy to spot.</p><pre>dt = datetime.now()<br>extraction_id = &quot;xyz&quot;<br>df = df.with_columns([<br>    pl.lit(dt).alias(&quot;_extraction_date&quot;),<br>    pl.lit(extraction_id).alias(&quot;_extraction_id&quot;),<br>])</pre><p>A common use case of transformations in this step is the conversion of data types. One I had to do, is date unit conversion. The tool we use for querying the datalake in my company does not support dates in micro or nanoseconds precision. The function below automatically detects date-time columns using the `dtype` attribute and casts them no milliseconds.</p><pre># This function will find all timestamps and cast them to the &quot;ms&quot; unit<br>def date_to_ms(df: pl.LazyFrame) -&gt; pl.LazyFrame:<br>    for ix, col_type in enumerate(df.dtypes):<br>        if col_type == pl.Datetime:<br>            logging.info(f&quot;Going to cast column {df.columns[ix]} from {col_type} to datetime[ms]&quot;)<br>            df = df.with_columns(<br>                [pl.col(df.columns[ix]).dt.cast_time_unit(&quot;ms&quot;).alias(df.columns[ix])]<br>            )<br>    return df</pre><p>A cool trick I have not talked about in this post is the fact that these dataframes are actually `LazyFrames`. This is commonly referred to as Lazy execution, instead of eager execution. In practice, when you add `.lazy()` to a `DataFrame`, it becomes a `LazyFrame`, and most operations will be added to an execution plan. Polars will try to optimize the plan and execute all operations only when they are needed. In our case, this will be when calling the “write” call or the `.collect()` function. Running `df = df.with_columns` with a single column in a loop will yield the same result as adding them all in the same function call.</p><h3><strong>Two important things to note</strong></h3><ol><li>If you read the documentation of ConnectorX, you will find a partition_on option. However, it does not accomplish the same results as the partitioning approach I described earlier. ConnectorX’s partitioning is aimed at achieving faster data extraction through parallel queries. This may be useful if you are scaling vertically and prioritizing speed over cost. However, in my use cases, I found the approach I described to be more useful for cost optimization.</li><li>Apache Spark is also very good at partitioning workloads. The way it does it is similar to what I presented, but its all implemented behind the scenes. Spark distributes the job between the number of workers you make available to the workload. This will attempt to execute the queries in parallel and can be a lot more expensive to run (also because it’s written in Scala, and it is a lot less resource-efficient). There are distributed frameworks in development for Apache Arrow, but I have yet to explore them. Another thing to know about doing things distributed is that running operations that depend on values of multiple rows, like aggregations, might need to introduce a lot of communication between the workers.</li></ol><h3><strong>Conclusion</strong></h3><p>Creating a datalake with minimal modifications to the tables can get you a long way. It will be easier to deal with schema changes coming from the applications, and in small teams, it will allow developers to contribute as well.</p><p>All other operations can be done directly in the data lake. From simple aggregations and joins to hundreds of lines of SQL queries, you can accomplish anything using tools such as Polars and other Apache Arrow-based libraries. If you prefer processing data with SQL, the DuckDB library is also a great option. By performing these operations on top of Parquet files, you won’t add any load to production databases, and you’ll benefit from many optimizations that can improve analytical queries.</p><p>If you want a complete code example, check it out on <a href="https://github.com/auyer/polars-extraction">GitHub.com/auyer/polars-extraction</a> !</p><p>This article was originally posted to my personal page, here: <a href="https://rcpassos.me/post/lightweight-large-etls-with-polars-connectorx">rcpassos.me/post/lightweight-large-etls-with-polars-connectorx</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4936ea605f58" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I Decreased ETL Cost by Leveraging the Apache Arrow Ecosystem]]></title>
            <link>https://medium.com/@rcpassos/how-i-decreased-etl-cost-by-leveraging-the-apache-arrow-ecosystem-37b6d076bd54?source=rss-e354c9e0c053------2</link>
            <guid isPermaLink="false">https://medium.com/p/37b6d076bd54</guid>
            <category><![CDATA[apache-spark]]></category>
            <category><![CDATA[cost-reduction]]></category>
            <category><![CDATA[etl]]></category>
            <category><![CDATA[apache-arrow]]></category>
            <category><![CDATA[data-engineering]]></category>
            <dc:creator><![CDATA[Rafael "Auyer" Passos]]></dc:creator>
            <pubDate>Wed, 15 Feb 2023 01:31:33 GMT</pubDate>
            <atom:updated>2023-04-06T16:35:54.692Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>In the field of Data Engineering, the Apache Spark framework is one of the most known and powerful ways to extract and process data.<br>It is well-trusted, and it is also very simple to use once you get the infrastructure set up.<br>Understandably, most engineers will choose it for every task.<br>However, in a lot of ways, it can be overkill. And a very expensive one.</blockquote><h3>Our data platform journey</h3><p>In our stack, we manage several databases for different micro services that our team built.<br>We also have a few legacy databases for two platforms built by external companies.<br><br>To bring insights and enable data-driven decision-making for our directors, we needed a way to run analytical queries on all of them.<br>Enabling it requires we run ETLs (extract, transform, and load scripts) to get data from the databases into our Data Lake.<br><br>At the time of writing this article, I am the professional responsible for most of the data integrations and extractions at my company. <br>And I was also the lead architect for our data platform and infrastructure, and I will explain how it evolved into what we have today.</p><h4>Extraction Jobs: what an ETL looks like</h4><figure><img alt="ETL (Extract Transform Load) diagram" src="https://cdn-images-1.medium.com/max/898/1*q6I1WcWM_Pp8lkbKs7KCEA.png" /><figcaption>ETL (Extract Transform Load) diagram</figcaption></figure><p>The first iteration of our ETL system used the AWS Glue Jobs service. <br>It was easy to get started with since it is a serverless offering of Apache Spark (with some customizations on top).<br><br>These extractions would take all data from the databases and save all of it as Apache Parquet files in an S3 bucket, separating databases into folders, and their tables as subfolders.<br>We use AWS Athena (similar to the Open Source Presto/Trino project) to run SQL queries on all these files as if it was one big Data-Warehouse.<br><br>At the end of the stack, we have Metabase as our visualization tool, for making beautiful dashboards.<br>These last two are still part of our stack. We&#39;ve tested different projects, like Dremio and Trino for running the queries, and also Apache Superset for the viz, but ended up sticking with our first choices.<br>What I changed the most is how we run the extraction scripts.<br><br>The first change was to migrate a few ETLs to AWS EMR (Managed Apache Spark clusters).<br>These scripts had become too complex to run on Glue, and on EMR we can scale the cluster as we wish. <br>The cost of running them was also a good reason to migrate since AWS Glue can be a lot more expensive than the alternatives.<br><br>The second step was to relinquish Amazon&#39;s help in managing these clusters and do it myself on Kubernetes.<br>I used Spark <a href="https://github.com/GoogleCloudPlatform/spark-on-k8s-operator">spark-on-k8s-operator</a> to run our Spark Jobs.<br>It made them a lot faster (start-up times for EMR are painfully slow), cheaper, and easier to manage.<br>With this operator, jobs are submitted as Kubernetes custom resources, and the operator creates all necessary pods to run the scripts.<br><br>Up to this point, we&#39;ve been writing Apache Spark scripts and only changing how and where we run them. The last step is different. <br>Using Apache Arrow and just simple containers, I made most of the old extractions obsolete.</p><h3>Apache Spark vs Apache Arrow (not equivalent)</h3><p>Apache Spark is made for distributed work. <br>For this, it is usually set up in a cluster with one or a few driver/master nodes, and at least a few executor nodes. <br>This is amazing when you need to work with large datasets, and they can&#39;t fit into the memory of one reasonably priced machine.<br>But there is always a downside. Even when this is the case, distributing the processing will not always be perfect.<br>It could be necessary to share data between nodes, and this causes a lot of network traffic.<br>And some operations just need data to be in memory.<br><br>In the other case, when the workload is not that large, distributing it will yield no real gain. <br>It will most likely hurt it due to various types of overhead like synchronization and transport.<br>You can run Apache Spark without a cluster, but it was not made for that.<br>For this reason, I decided to test some new projects that would do what I needed without being distributed.<br><br>The tools I used to create our new extractions are [Polars](https://www.pola.rs/) and [ConnectorX](https://github.com/sfu-db/connector-x).<br>Polars is a dataframe library, like pandas, but implemented in Rust with the Apache Arrow data model. <br>It is a columnar data model, and it was created to be implemented in any language. <br>But that&#39;s not the impressive part: you can share data between totally different code bases, like Rust, Java, and Python, without serializing and even reallocating it.<br>If you can access the same space in memory, you can use it with the Arrow ecosystem.<br>When I said Spark shuffles cause a lot of traffic over the network, it also requires all this data to be serialized before sending and de-serialized at the receiving end.<br>This wastes a lot of time and resources.</p><h3>Code Time</h3><p>ConnectorX is integrated into Polars, and if both are installed, you can call polars.read_sql.<br>I will use it directly though:</p><pre>import connectorx as cx<br><br>arrow_table = cx.read_sql(<br>    query=&quot;select * from table_x&quot;,<br>    conn=&quot;postgres://user:pass@host:port/database&quot;,<br>    return_type=&quot;arrow2&quot;,<br>    protocol=&quot;binary&quot;,<br>)py</pre><p>My example uses Postgres, but ConnectorX supports several other databases.<br>The output of this function is an Apache Arrow Table. <br>Arrow2 means it uses the unofficial Rust implementation <a href="https://github.com/jorgecarleitao/arrow2">Arrow2</a>.<br>There is also the official Apache Arrow implementation in Rust, and a C++ implementation used by PyArrow.<br><br>This next call instructs Polars to read the arrow table memory space. And as the Docs say:<br>This operation will be zero copy for the most part. <br>Types that are not supported by Polars may be cast to the closest supported type.</p><pre>import polars as pl<br>df = pl.from_arrow(arrow_table)</pre><p>Once you loaded it into Polars, you can manipulate this data at will.<br>There is an option to turn it into a lazy operation like it is done with Apache Spark.<br>This is very useful because it allows Polars to optimize the query plan when possible.<br>This also enables the use of streaming, for larger-than-memory operations.<br><br>In this sample, I will keep it simple and write it to a file directly.<br>This could be done to a local path, or almost any destination [fsspec](https://filesystem-spec.readthedocs.io/en/latest/) supports.<br>For example, one valid path could be `s3://bucket/database/folder/`. <br>If you do not specify the file name, it will generate a random one. If you want to keep a single file, or want to replace an existing one, make sure to specify the file name.</p><pre>df.write_parquet(&quot;output.snappy.parquet&quot;, compression:&quot;snappy&quot;)</pre><p>It is also possible to use PyArrow to do this. <br>As I said before, PyArrow uses the C++ implementation of Arrow.<br>But data can flow between them seamlessly without the need for serialization, or even memory copying.</p><pre>import pyarrow.parquet as pq<br><br>pq.write_table(<br>    df.to_arrow(),<br>    where=&quot;output.snappy.parquet&quot;,<br>    compression=&quot;snappy&quot;,<br>)</pre><p>I created an example repository in GitHub that puts all of this together. Check it out!<br><a href="https://github.com/auyer/polars-extraction">github.com/auyer/polars-extraction</a></p><h3>Conclusion</h3><p>Apache Spark is an established framework for building complex ETLs.<br>But it carries a heavy JVM stack behind it.<br>As we discussed here, it is not a good choice for small datasets if you are worried about cost (you should be).<br><br>The Apache Arrow ecosystem is growing.<br>It can&#39;t replace Spark just yet, but one day I bet it will.<br>But when doing what it is able to do now, it does it a lot faster and consumes fewer machine resources.<br>With new features being implemented into Polars almost every week, it will soon be the ubiquitous tool for data frames.<br><br>ConnectorX is an important piece for this success. It does not have all the features it needs to make Polars fully replace Spark for me, as it does not support all Postgres Types.<br>I implemented support for a few, like Enum and ltree, but others are still missing, like string arrays. It could receive more love from the community.<br><br>Hope this article was worth reading! Thanks!</p><p>Originally Posted on <a href="https://rcpassos.me/post/apache-arrow-future-of-data-engineering">https://rcpassos.me/post/apache-arrow-future-of-data-engineering</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=37b6d076bd54" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Writing LaTeX Documents In Visual Studio Code With LaTeX Workshop]]></title>
            <link>https://medium.com/@rcpassos/writing-latex-documents-in-visual-studio-code-with-latex-workshop-d9af6a6b2815?source=rss-e354c9e0c053------2</link>
            <guid isPermaLink="false">https://medium.com/p/d9af6a6b2815</guid>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[latex]]></category>
            <category><![CDATA[vscode]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[overleaf]]></category>
            <dc:creator><![CDATA[Rafael "Auyer" Passos]]></dc:creator>
            <pubDate>Fri, 31 Aug 2018 14:03:56 GMT</pubDate>
            <atom:updated>2024-01-22T13:10:37.736Z</atom:updated>
            <cc:license>http://creativecommons.org/publicdomain/zero/1.0/</cc:license>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZqWw2A3PDyIK1_-Apjjv3Q.png" /><figcaption>LaTeX Workshop on VS Code</figcaption></figure><blockquote>If you want to write LaTeX on your machine, VS Code is a great option for you! Installing all the necessary packages is a simple process. And with the power of Git, you can sync with web-based editors like Overleaf, and have satisfying versioning and backup.</blockquote><h3>Why LaTeX ?</h3><p>For the uninitiated, LaTeX is not an editor, but a typesetting system. There are a few very compelling reasons why someone might want to use LaTeX instead of the conventional text systems. For me, these are the three most important:</p><ul><li>Focus on Content first, and let LaTeX deal all the formatting</li></ul><p>First, the clear separation between formatting and content allows you to focus on developing your content. That means you wont need to re-format the whole document at each iteration.</p><p>Image (and table) numbering and the summary is also a big deal with LaTeX. You will not manually add numbers to any of them, you will define labels and reference those in your source. When compiling, LaTeX will worry about the order and numbering.</p><p>On top of all of that, there are a ton of LaTeX templates out there, and they make your job a lot easier. It is also not that hard to customize them when you get used to it.</p><ul><li>Easy Citations</li></ul><p>Never worry about the citation style again. Once you chose the right one for your document, all you need to do is put the <em>bibtex</em> citations (that most sites give you, including Google Scholar) in your bib file, and reference them in your text.</p><ul><li>High-quality typography</li></ul><p>If you are writing any technical document, you might need some formulas or special symbols. The quality of those in LaTeX is unmatched in any other editor. All letters and symbols will look as crisp as they can be.</p><p>Convinced yet? If not, you might what to google about it, or read this articles:</p><ul><li><a href="https://medium.com/@marko_kovic/why-i-write-with-latex-and-why-you-should-too-ba6a764fadf9">Why I write with LaTeX (and why you should too)</a> by Marko Kovic</li><li><a href="http://scottmcpeak.com/latex/whatislatex.html">What the heck is Latex? </a>by Scott McPeak</li></ul><h3>Installing your tools</h3><p>The installation process can be a little bit different for each system, but the process should be very straightforward. In some systems, you will have multiple options to download. I recommend taking the most complete packages ( without GUI ). They are less likely to give you a headache trying to install additional libraries later.</p><p>Some common Linux commands for installing LaTeX are:</p><pre># Arch Linux Family<br>sudo pacman -S texlive</pre><pre># For Ubuntu, you might need a ppa:<br>sudo add-apt-repository ppa:jonathonf/texlive<br>sudo apt update &amp;&amp; sudo apt install texlive-full</pre><pre># Fedora<br>sudo dnf install texlive-scheme-full</pre><p>In MacOS, I chose to install MacTeX without any GUI application, afterall, I am going to use VS Code for that. But if you desire to keep the GUI apps, just remove the “no-gui” from the name. If you dont have <a href="https://brew.sh/">homebrew</a> ( brew command), install it. It is a very handy tool for installing Terminal tools and even a few community apps.</p><p>After the installation is complete, it is necessary to update the LaTeX packages with the <em>tlmgr</em> command line tool that already comes with MacTeX.</p><pre># macOS MacTex Install<br>brew --cask install mactex-no-gui</pre><pre># Updating the packages<br>sudo tlmgr update --self &amp;&amp; sudo tlmgr update --all</pre><p>Now, let us install LaTeX Workshop plugin from the Visual Studio Code Marketplace.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*rOhWQl44Fd5pVS0qNUSkoA.png" /><figcaption>Extensions Page in VS Code</figcaption></figure><p>Or install it by running the following command in the command pallete:</p><pre>ext install latex-workshop</pre><p>At this point, if you open a TeX file, you should be able to see it working, and your screen will be comparable to the one in the image below. <br>When clicking the preview option, you will have a choice to see the document in another tab of VS Code, or in a different app. If you opt for the tab, you are going to get a layout similar to the one in the first picture of this article.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*O4DBvTZ6qRC7mRXQ3w1ThQ.png" /><figcaption>Latex Plugin Main Options</figcaption></figure><p>By default, your document will be recompiled automatically on save. With this, the whole process of delivering the PDF becomes an automated process. All you need to do is pick the file from your folder, and its ready to go.</p><h3>LaTeX + GIT</h3><p>If you are a developer, you might be used to versioning everything (hopefully). So why not use GIT in your LaTeX documents as well?</p><p>If you are only editing it locally, it is just as simple as creating any other repository. But this starts shining when you want to work with others, or you want people to be able to check your work without you heaving to send it to them every time. On top of that, uploading your content to a remote GIT repository can protect you in case of a catastrophic failure in your personal machine.</p><pre>git init<br>git add <em>your_files_here</em><br>git commit -m &quot;The commit message&quot;<br>git remote add origin https://github.com/<em>username/repo</em><br>git push -u origin master</pre><p>It is recommended to use a .gitignore file to keep your repository free of temporary files, and any side products created during compilation.</p><p>I recommend using the pre-built one from the <a href="https://github.com/github/gitignore/blob/master/TeX.gitignore">github.com/github/gitignore</a> repository.</p><h3>Integrating with Overleaf</h3><p>Overleaf and ShareLaTeX are two of the most popular LaTeX web editors out there. The two platforms are joining forces into the “Overleaf V2”. Overleaf had an interesting GIT feature in version 1, that has evolved into a GitHub sync feature in version 2. It is not clear if this is going to be a free feature or not. It is a premium feature for ShareLaTeX, but free for Overleaf v1 users.</p><p>When creating a new project, there is an option to import it from GitHub:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/222/1*GFmBFvDCbmyuJC0-cvh8eg.png" /><figcaption>Overleaf v2 New Project Page</figcaption></figure><p>If you cant see this option, you might need to activate it somewhere.</p><p>This feature works with private repositories as well. And all you need to do is authorize Overleaf by logging into your GitHub account.</p><p>Now, when you open the Menu, there is an option to Sync with GitHub. The panel shown in the picture below is where you can PULL and PUSH changes to your Git repository. This way you can keep your collaborators up to date with what you’ve created offline, and you can work from a different computer when you need/desire. Neat!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*NSIkHOVTVWpidvCbW8IXLQ.png" /><figcaption>GitHub Sync Pannel</figcaption></figure><h3>Conclusion</h3><p>If you are comfortable with VS Code, it might just be your best bet at writing LaTeX on your machine. The possibility of synchronizing your local repository with a web-based collaboration tool allows you to keep writing without internet in your local copy, or without your computer in the web editor.</p><p>I hope this article was useful for you. Might any question pop up, do not hesitate in posting a comment! Thanks!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d9af6a6b2815" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>