Gediminas Lelešius

Typesetting in LaTeX (Eng & Lt)

2021-12-13, U: 2022-05-22

Short guide how to prepare Computer Science or Physics homework using \LaTeX.


Windows: install MiKTeX
Linux: install texlive or similar using your packet manager.

User TeXWorks or text editor to edit .tex files.

Compile using pdflatex --shell-escape --output-directory=out --aux-directory=out file.tex to build. Last two options put all auxiliary and output files to out folder.

Quick previews can be generated using LaTeX JS Playground

Getting started

Just write text between \begin{document} and \end{document}.
Write comments (will not be outputed to pdf) after % (until end line).
Multiple spaces are outputed as one, new line is outputed as space.
Empty line starts new paragraph. Insert line break with \\.


Start sections with \section{section title}.
Further sectioning:

\section{section title}

To add a (sub)section without a number, use \section*{title}, \subsection*{title}, etc.


Inline math: $x^{2.2} = a_1$ x^{2.2} = a_1.
Math in new paragraph: $$ \sum_{i=0}^n i = \dfrac{n(n+1)}{2}$$.

\sum_{i=0}^n i = \dfrac{n(n+1)}{2}

Quotation Marks

English: `` (backticks) '' (single quotes)

Lithuanian: ,, (commas) `` (backticks)
Alternatively, you can use " everywhere. Add this to preamble (Lithuanian and german quotes are the same):



About dashes - VLKK. I believe rules are similar in British English.

Hyphen (brūkšnelis) -: used between number and suffix (e.g. 3-iąją), between two words that describe a name of some thing or feature (lopšelis-darželis). Should NOT be surounded by spaces.
En-dash (brūkšnys) --: used to show ranges (e.g. 100--150), as a punctuation mark (ruduo -- blogiausias metų laikas). Should be surounded by spaces.
Em-dash (skyrybos brūkšnys) ---: not used in Lithuanian.


~ inserts non-breaking space.
\;, \:, \, spaces from wider to narrower.
\[SPACE] forces space to be normal. Useful after a dot because LaTeX assumes that all dots end sentences and makes following spaces larger: e.g.\ banana.



Italics: \textit{text} text
Bold: \textbf{text} text
Small caps: \textsc{text}
Monospace: \texttt{text} text



    \item First
    \item Second
  1. First
  2. Second

Bullet points:

    \item Point
    \item Point
  • Point
  • Point

Custom indexed:

\begin{enumerate}[label=\alph*] % a b c
\begin{enumerate}[label=\roman*)] % i) ii) iii)
\begin{enumerate}[label=\textit{(\Alph*)}] % (A) (B) (B) in italics

Aligned math

Aligns & symbols (they aren't displayed).

    A &= \sum_i b_i\\
    &= c+d+e+\sin{x}\\
    \sin{\prod_{j} y_j^{10}}&<10
\begin{align*} A &= \sum_i b_i\\ &= c+d+e+\sin x\\ \sin{\prod_{j} y_j^{10}}&<10 \end{align*}


Insert urls with \url{}.


Inline: \includegraphics[width=5cm]{FILENAME}

On its own ([H] inserts in the same place as in source, remove it to allow LaTeX to pick the location automatically, width can be in cm, fraction 0.5\textwidth, etc.):



        \includegraphics[width=\textwidth]{FILE A}
        \caption{CAPTION A}
        \includegraphics[width=\textwidth]{FILE B}
        \caption{CAPTION B}

Wrap Figures

Wraps text around the figure. I don't recommend using unless absolutely needed. Ignores page margins, so check position carefully.
Side should be left or right.


Highlighted code

Install Python3, run pip install Pygments. Embed code using \inputminted{LANGUAGE}{CODEFILE} or

let knot (f: (int -> int) -> int -> int) : int -> int =
    let r = ref (fun n -> 0) in
    let recur = fun n -> !r n in
    let () = r := fun n -> f recur n in


\begin{tabular}{l c r}
    A & B & C \\
    D & E & F \\
    left & center & right \\
left center right

l c r specify that there will be three columns aligned left, center, and right respectively. Spaces indicate that columns will be separated by spaces.
c|c: two centered columns separated with single border line.
& separate columns, \\ end rows.

    \textbf{text text} & \textbf{more text} \\ \hline
    $x^2$ & E \\ \hline
text text more text
x^2 E

table works similarly to figure.
\hline adds horizontal lines, in this case before the first row, after the first row and after the second row.

Multiple Files

You can move part of the tex file to another tex file and include it using \input{filename.tex}. That will simply paste contents of filename.tex.


Create labels to (sub)sections, enumerate items, figures, tables, etc. using \label{UNIQUE ID} after \section, \item, or \caption command.

\section{My section}\label{mylabel}


Insert a footnote by using \footnote{text}.
Alternatively, mark footnote position using \footnotemark{} and add text later (but before next footnote mark) with \footnotetext{text}.

Table of Contents

\tableofcontents{}, \listoffigures{}, \listoftables{}.

Multiple Columns

You can have some part of the document in multiple columns by using multicols environment:


Useful Resources

Find math symbol name (Detexify)
Latex word count (TeXcount)
Table generator


% template.tex
% Lithuanian
% recomended
% \usepackage[sorting=none]{biblatex}

Main document

% preamble
% preamble ends




Document Class

article is good for small to medium documents.
For larger ones you might use report (has \chapter, \appendix).
You can also create presentations using beamer.


Should be used no matter the language.



Table, Picture, Table of Contents, Biobliography and others are in English by default.


Common Mistakes

Copying text from PDF and pasting results in unknown symbol errors.
Solution: replace symbols to proper ones or add to preamble: \DeclareUnicodeCharacter{symbolcode}{latexsymbol} where symbolcode is 4 digit symbol code and latexsymbol is latex symbol to typeset.

BibTeX error when using TeXWorks and no \cite is used.
Solution: use \nocite{*} or disable BibTeX.

Citation references not found.
Possible cause: forgot to rerun BibTeX.

Error inside align: ! Paragraph ended before \align* was complete. <to be read again> \par.
Cause: empty line inside align (empty lines are replaced by \par).
Remove empty line. Line breaks are insert using \\.



Use biblatex package.
Create filename.bib file, add references here.
Use file by adding \addbibresource{filename.bib} to preamble.
Cite items using \cite{REFNAME}.
Insert bibliography section: \printbibliography{}

For urls use:

  author = {{AUTHOR}},
  title   = {TITLE},
  howpublished = "\url{URL}",
  note = "Visited on DATE"

Spell checking

Install pandoc.

First option: convert to docx using pandoc filename.tex -t docx -o filename.docx.
Use Word spell checker.

Second option: Create Lua filter file filter.lua with code given below (or remove --lua-filter argument).
Convert to text using pandoc filename.tex -t markdown_github --wrap=none --lua-filter filter.lua -o filename.txt.
Use any text spell checker.

function Image () return {} end
function Link (link) return link.content end

local function to_remove(el)
    return el and (el.t == 'Cite' or el.t == 'Image' or el.t == 'Math' or el.t == 'Span')

function Inlines (inlines)
    for i = #inlines, 1, -1 do
        if to_remove(inlines[i]) then
    return inlines

Tracking ToDos

Add this to preamble.

%TC:macro \pending 1

\newcommand{\pendingonline}[3]{\item\textbf{\hyperref[todo:#1]{#1} on #2}: #3}



Use \pending{text} to insert ToDo items in text, \pendinglist{} to insert section of all ToDos.

List with referencable names

\setlist[refitemize]{label=\refitemval:~, ref=\refitemval, wide=0cm}

Create a list with \begin{refitemize}\end{refitemize}.
Insert elements with \item{Item name}\label{LABEL} text.
Reference items later with \ref{LABEL}. Item name will be shown as reference.


  • page layout
  • title
  • page numbering style
  • custom commands