LaTeX for Fun and Profit

2 minute read

Published:

LaTeX plays an essential role in computer science academics. A decent layout leads to the entertainment of both reviewers and ourselves. Believing this, I write the following to demonstrate some tips of LaTeX best practice.

Vector Graphics

In most circumstances, a vector graphic performs better than a pixel-based graphic on document rendering. So is as discussed in Writing for Computing Science:

Writing for Computer Science (Chapter 11 / Page 166) The generation of images in vector format (postscript, PDF, SVG) rather than raster format (jpg, gif, png) to allow subsequent rescaling.

Here I demonstrate an example of generating a vector graphic (PDF format) through Microsoft PowerPoint.

Open your PowerPoint file, and select the graphs you want to export. Right-click on the selection and export the graphics as the file.

save-image-as-file

PowerPoint: save graphics as a file

as-pdf

PowerPoint: as PDF format

Import the pdf file as graphics in your LaTeX projects:

\begin{figure}[!t]
    \centering
    \includegraphics[width=0.8\linewidth]{your-graphic.pdf}
    \caption{Your Amazing Caption}
    \label{fig:your-graphic}
\end{figure}

Code Highlighting

2 LaTeX packages can highlight code listings: minted and lstlisting. Here I am not talking about the pros and cons of the two packages. Instead, I will only list the examples.

Following is a basic snippet of minted code highlighting.

\usepackge{minted}  % import minted

\begin{listing}[!t]
\label{lst:your-awesome-code}

% Set minted attributes.
% For more attributes, reference https://ctan.org/pkg/minted
\setminted[js]{
    xleftmargin=4mm,
    frame=lines,
    framesep=2mm,
    baselinestretch=1,
    fontsize=\footnotesize,
    tabsize=4,
    linenos,
    numbersep=4pt,
    fontfamily=tt,
    breaklines}
\definecolor{darkred}{rgb}{0.7, 0.0, 0.0}

% Here begins the code
\begin{minted}[highlightlines={},samepage,escapeinside=~~]{js}
function(obj) {
  ...
}
\end{minted}
\end{listing}

minted-code

Code highlighting rendered by minted package

If you want more sophisticated code highlighting with customized marks and quotations, the following steps may help:

  1. Create a blank object
  2. Setup minted, enter your code
  3. Compile to PDF file and import to your graphic design software (e.g. Microsoft Powerpoint)
  4. Re-generate to PDF file

Note: Please keep each PDF file as clean as possible (no extra words). Note that cropping the PDF file cannot achieve this. The unwanted words in your final PDF file may disturb the reviewers.

Clever Reference

Using general cross-referencing in LaTeX only produces the label number. The reference type (figure, chapter, equation) must be added manually. The cleveref package overcomes this limitation by automatically producing the label name and number.

\usepackge{cleveref}    % import package

...\label{lab:test}     % label here

\cref{lab:test}         % generate reference

Colorized Editing

Distributed writing for one essay has been a common practice among the research teams. Colorized editing will remarkably improve your writing experience.

\usepackge{xcolor}  % import package
                    
% define commands
\newcommand{\rick}[1]{\textcolor{orange}{Rick:#1}}
\newcommand{\astley}[1]{\textcolor{blue}{Astley:#1}}

\rick{Never gonna give you up.}

\astley{Never gonna let you down.}

color

Colorized editing

More Recommendations

Writing for Computer Science (3rd edition) is general guidance on performing and describing the research. It discusses reading and reviewing, communication, hypotheses, questions, evidence, writing, and so many details about academic writing, with complete examples provided. Hopefully, it brings you excellent academic achievements.