<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Seshal Jain</title>
    <description>The latest articles on DEV Community by Seshal Jain (@seshaljain).</description>
    <link>https://dev.to/seshaljain</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F263396%2F7d33e66f-cf81-4da1-be37-4d5708728387.jpeg</url>
      <title>DEV Community: Seshal Jain</title>
      <link>https://dev.to/seshaljain</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/seshaljain"/>
    <language>en</language>
    <item>
      <title>Using Emacs for College Assignments</title>
      <dc:creator>Seshal Jain</dc:creator>
      <pubDate>Sun, 24 Jan 2021 04:53:19 +0000</pubDate>
      <link>https://dev.to/seshaljain/using-emacs-for-college-assignments-3ji5</link>
      <guid>https://dev.to/seshaljain/using-emacs-for-college-assignments-3ji5</guid>
      <description>&lt;p&gt;In the 3rd Semester of my Bachelor of Technology in Computer Science course at MANIT, Bhopal, I came across &lt;a href="https://www.gnu.org/software/emacs/" rel="noopener noreferrer"&gt;Emacs&lt;/a&gt;. I won't be lying when I say it changed my life.&lt;/p&gt;

&lt;p&gt;I use Emacs for all my text-based work (more posts on this coming soon!), and it naturally made sense for me to experiment with it for my programming lab assignments.&lt;br&gt;&lt;br&gt;
The general workflow of the labs I am currently enrolled in is something like this:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Professor assigns some task, ex. &lt;em&gt;Analysis of Various Sorting Algorithms&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;The student writes relevant code/explanation for the given program&lt;/li&gt;
&lt;li&gt;The student runs the program in a console, takes screenshots, and prepares a document in Word/Docs&lt;/li&gt;
&lt;li&gt;The student mails a generated PDF (or even the original file) to the professor&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I realised in the first few weeks that this is a very cumbersome process, since we're dealing with images and syntax highlighting.&lt;br&gt;&lt;br&gt;
It does not make any sense to paste code from an IDE into a word processor, where it loses the syntax highlighting or worse, is typeset into an unreadable sans-serif typeface (Calibri, I'm looking at you) 😩.&lt;/p&gt;

&lt;p&gt;I was exploring &lt;a href="https://orgmode.org/" rel="noopener noreferrer"&gt;Org Mode&lt;/a&gt; around the same time, and it is the perfect tool for this use case.&lt;br&gt;&lt;br&gt;
I now use literate programming to write and run source code in the same file as my explanation, and it is then exported to LaTeX natively by Org to general beautiful, publication-ready PDFs.&lt;br&gt;
Additionally, since all of it is in plain text, I also host my assignments in version control on &lt;a href="https://github.com/seshaljain/semester-four/" rel="noopener noreferrer"&gt;Github&lt;/a&gt;, where Org files are rendered like regular pages. Awesome 🔥!&lt;/p&gt;



&lt;p&gt;I have a fully custom Emacs config, you are welcome to check it out on &lt;a href="https://github.com/seshaljain/.doom.d" rel="noopener noreferrer"&gt;Github&lt;/a&gt;. However, you do not need the entire configuration, the tools should work natively with Emacs too!&lt;/p&gt;
&lt;h2&gt;
  
  
  Emacs Setup
&lt;/h2&gt;

&lt;p&gt;On Ubuntu, installing Emacs is as simple as&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;emacs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This should install Emacs 26.3 as of writing. Go on, launch your Emacs!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F6s9y833px4ql515nxkdl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F6s9y833px4ql515nxkdl.png" alt="Emacs 26.3 Fresh Install"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  TeX Setup
&lt;/h2&gt;

&lt;p&gt;I use &lt;a href="https://yihui.org/tinytex" rel="noopener noreferrer"&gt;TinyTeX&lt;/a&gt; because of its small footprint, but essentially all you need is a TeX processor.&lt;br&gt;&lt;br&gt;
You can find the install instructions on its website:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;wget &lt;span class="nt"&gt;-qO-&lt;/span&gt; &lt;span class="s2"&gt;"https://yihui.org/tinytex/install-bin-unix.sh"&lt;/span&gt; | sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will install &lt;code&gt;tlmgr&lt;/code&gt; and other TeX binaries on your system.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Note:&lt;/strong&gt; You might need to log out and log in again for the binaries to be accessible on your PATH.&lt;/p&gt;
&lt;h2&gt;
  
  
  Org
&lt;/h2&gt;

&lt;p&gt;Org files are saved with a &lt;code&gt;.org&lt;/code&gt; extension. Org is extremely powerful, with robust support for text formatting and source code blocks. This is extremely helpful, especially for us as you will see.&lt;/p&gt;

&lt;p&gt;All Org mode headings start with *, with the number of * indicating the depth.&lt;br&gt;&lt;br&gt;
You can add text as is, somewhat like Markdown. Check out all of Org Mode's features in the &lt;a href="https://orgmode.org/manual/" rel="noopener noreferrer"&gt;Org Mode Manual&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Now here's the interesting part. You can write source code inline within Org's source blocks, with complete support for syntax highlighting, code building and auto-completion. 😲&lt;/p&gt;

&lt;p&gt;For starters, you can use my &lt;a href="https://github.com/seshaljain/semester-four/blob/main/ada-lab/lab2/191112436.org" rel="noopener noreferrer"&gt;ADA Lab 2 Assignment&lt;/a&gt; file.&lt;br&gt;&lt;br&gt;
After opening it in Emacs, you will see that the code blocks are already being highlighted using C++ syntax.&lt;br&gt;
To edit the code, place the cursor somewhere inside the code block and press C-c '.&lt;br&gt;&lt;br&gt;
This will launch a C++ buffer where you can edit the file with C++ language support. Press C-c ' to confirm the changes or C-c C-k to cancel.&lt;/p&gt;

&lt;p&gt;As you may have noticed by now, Emacs is very keyboard intensive, you will learn the keybindings with practice over time.&lt;br&gt;&lt;br&gt;
You can also search for commands via M-x because almost everything in Emacs is a (searchable) function.&lt;/p&gt;

&lt;p&gt;Let's export this Org file now.&lt;br&gt;&lt;br&gt;
In the main Org file, enter C-c C-e to launch the Org Export window. There are a myriad of options available, feel free to play around! I especially like the UTF-8 export when submitting assignments in plaintext. Adds additional flair to your work 😉.&lt;/p&gt;

&lt;p&gt;Oh! By the way, press C-g almost anywhere in Emacs to cancel the current operation.&lt;/p&gt;

&lt;p&gt;To export the file to PDF via TeX, enter C-c C-e l p. This creates a TeX file from your Org file and uses LaTeX to convert it to a PDF.&lt;br&gt;&lt;br&gt;
…but wait! There seems to be an error! To open the error log, enter C-x C-b and select the buffer named &lt;strong&gt;* Org PDF LaTeX Output *&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
You will find a line stating the name of the missing package:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;! LaTeX Error: File `&amp;lt;packagename&amp;gt;.sty' not found.&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This is because TinyTeX is very minimal, it comes only with the bare minimum packages pre-installed. &lt;code&gt;tlmgr&lt;/code&gt; allows you to install all the TeX packages you need from the CTAN repository. When it shows an error, run the following command to install the relevant package:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;tlmgr &lt;span class="nb"&gt;install&lt;/span&gt; &amp;lt;packagename&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Once you install all the missing packages, you should see a &lt;code&gt;.tex&lt;/code&gt; and a &lt;code&gt;.pdf&lt;/code&gt; file on the same directory. Open up your very first Org-powered PDF!&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Protip:&lt;/strong&gt; You can open PDFs in Emacs too! Simple use C-x C-f on a PDF file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F2ywh2ebfd3rb4vjfhu0n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F2ywh2ebfd3rb4vjfhu0n.png" alt="PDF Reader in Emacs"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is pretty awesome, but you can do even better! &lt;code&gt;Minted&lt;/code&gt; adds syntax highlighting functionality to the &lt;code&gt;SRC&lt;/code&gt; blocks on LaTeX export.&lt;/p&gt;
&lt;h3&gt;
  
  
  Minted
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;Minted&lt;/code&gt; is a LaTeX package which uses Python's &lt;a href="https://pygments.org/" rel="noopener noreferrer"&gt;Pygments&lt;/a&gt; library to generate syntax highlighted code output. This is an external dependecy and also requires some Emacs configuration.&lt;/p&gt;

&lt;p&gt;Install &lt;code&gt;Pygments&lt;/code&gt; via &lt;code&gt;pip&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pip &lt;span class="nb"&gt;install &lt;/span&gt;Pygments
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; The &lt;code&gt;pygmentize&lt;/code&gt; binary must be accessible on your PATH after installation.&lt;/p&gt;

&lt;p&gt;Install &lt;code&gt;minted&lt;/code&gt; via &lt;code&gt;tlmgr&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tlmgr install minted
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have installed the external dependencies, now we need to configure Emacs to use these.&lt;/p&gt;

&lt;p&gt;Navigate to the &lt;strong&gt;* scratch *&lt;/strong&gt; buffer. Switch to Org mode using M-x org-mode [RET].&lt;/p&gt;

&lt;p&gt;Create a Org source block by entering  [TAB] and add &lt;code&gt;emacs-lisp&lt;/code&gt; as the language.&lt;/p&gt;

&lt;p&gt;The block should now look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#+BEGIN_SRC emacs-lisp

#+END_SRC
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this source block, add the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight common_lisp"&gt;&lt;code&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;setq&lt;/span&gt; &lt;span class="nv"&gt;org-latex-listings&lt;/span&gt; &lt;span class="ss"&gt;'minted&lt;/span&gt;
      &lt;span class="nv"&gt;org-latex-packages-alist&lt;/span&gt; &lt;span class="o"&gt;'&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="s"&gt;""&lt;/span&gt; &lt;span class="s"&gt;"minted"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
      &lt;span class="nv"&gt;org-latex-pdf-process&lt;/span&gt;
      &lt;span class="o"&gt;'&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"&lt;/span&gt;
        &lt;span class="s"&gt;"pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"&lt;/span&gt;
        &lt;span class="s"&gt;"pdflatex -shell-escape -interaction nonstopmode -output-directory %o %f"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can execute this code, &lt;em&gt;right here, in this file&lt;/em&gt; by using C-c C-c. This will enable these features for your current session.&lt;/p&gt;

&lt;p&gt;To make these changes permanent, open the &lt;code&gt;~/.emacs.d/init.el&lt;/code&gt; file (create one if it does not exist) and add the Lisp code there.&lt;br&gt;
&lt;code&gt;init.el&lt;/code&gt; is a special file which is launched at Emacs startup.&lt;/p&gt;

&lt;p&gt;Congratulations, you now have a build process to generate beautiful assignments via LaTeX!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fpm6toakb4g4fyno51nt4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fpm6toakb4g4fyno51nt4.png" alt="Syntax highlighted PDF"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  tl;dr
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Org Mode in Emacs supports LaTeX export natively, but requires the TeX binaries to be installed and accessible on PATH&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;minted&lt;/code&gt; package uses &lt;code&gt;Pygments&lt;/code&gt; to add syntax highlighting to LaTeX exports&lt;/li&gt;
&lt;li&gt;Emacs can render PDFs natively&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Feel free to reach out to me via &lt;a href="https://twitter.com/seshaljain/" rel="noopener noreferrer"&gt;Twitter&lt;/a&gt; for any questions/suggestions! 😁&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Originally posted on &lt;a href="https://archgaelix.vercel.app/post/using-emacs-for-college-assignments/" rel="noopener noreferrer"&gt;archgaelix&lt;/a&gt;&lt;/em&gt;.&lt;/p&gt;

</description>
      <category>emacs</category>
      <category>latex</category>
    </item>
  </channel>
</rss>
