Written by Ana Žegarac.

  1. Organising your LaTeX project
    1.1. Project hierarchy
    1.2. Partitioning your LaTeX code
  2. Creating graphics
    2.1. Creating figures in TikZ
         2.1.1. Trigonometric unit circle
         2.1.2. Commutative diagrams
         2.1.3. Long exact sequence
    2.2. Importing figures from Inkscape
    2.3. Importing figures from MATLAB
  3. Other tips
    3.1. Naming labels
    3.2. Finding symbols

In this lecture we share ideas on how to effectively organise your $\mathrm{\LaTeX}$ projects and we cover some basics of working with graphics.

1. Organising your project

1.1. Project hierarchy

If you write more than one document in a given field, chances are that you will be reusing references and custom commands across many projects. To make your life easier, you might want to consider having all bibliographic entries and all custom commands in their own files. For the sake of this post, we name these files mybibliography.bib and mystyle.sty. For the bibliography file and the style file to be easily accessible from the other projects, we suggest keeping these files in the parent folder of your current project (called myproject in the illustrations below). More precisely, the following file hierarchy might be beneficial:

mylatexprojects
├── mybibliography.bib
├── mystyle.sty
└── myproject

In the rest of this section, we give tips on how to easily populate mybibliography.bib, what the contents of mystyle.sty should be, and how to make $\mathrm{\LaTeX}$ aware of where these files are.

Populating mybibliography.bib

The entries in mybibliography.bib consist of bibliographic data, as explained in Learning $\mathrm{\LaTeX}$ Lecture 5. You can find bibliographic data for books and papers on AMS' MR Lookup or Google Scholar. In the author's experience, Google Scholar has a larger database, but sometimes the data is wrong or missing (so do not copy-paste things blindly, always double check!). MR Lookup usually has far more detailed entries.

Tip: if you use data from MR Lookup, you might want to change the label of the entry to firstauthorYYYYfirstword. This way, for example the Introduction to Symplectic Geometry by Dusa McDuff and Dietmar Salamon published in 2017 would have a label mcduff2017introduction. Of course, in the actual bibliography all the relevant data will be displayed. The label mcduff2017introduction will only be visible to you.

Contents of mystyle.sty

The first line of the mystyle.sty file should be \ProvidesPackage{mystyle}. As the name indicates, this tells $\mathrm{\LaTeX}$ that the file provides the package mystyle. In our main file, we can then include this file using \usepackage command. The contents of mystyle.sty should be (almost) all your other \usepackage directives, and custom commands.

Making $\mathrm{\LaTeX}$ aware of where mybibliography.bib and mystyle.sty are

Let us assume your file structure is as follows:

mylatexprojects
├── mybibliography.bib
├── mystyle.sty
└── myproject
    └── main.tex

Then to use mybibliography.bib and mystyle.sty from main.txt, you have to write

\usepackage{biblatex}
\addbibresource{../mybibliography.bib} 

either in mystyle.sty or in the preamble and

\usepackage{../mystyle}

in the preamble. The symbols ../ tell $\mathrm{\LaTeX}$ to look for files in the parent folder of the current folder. Since the current folder is the one in which main.tex is located (i.e. the current folder is myproject), then this will ensure $\mathrm{\LaTeX}$ looks for both mybibliography.bib and mystyle.sty in the folder mylatexprojects.

1.2 Partitioning your code

In bigger projects (such as a bachelor or a master thesis), it is often more convenient to work with a number of smaller files, as opposed to one big file. One way to achieve this is by using the subfiles package. An advantage of the subfiles package is that it allows you to compile individual files, as well as the whole project.

Let us assume that our project's name is mythesis. We now divide up the files so that each chapter of our thesis is in a separate file. In the author’s limited experience, the following file structure proved to be the easiest to work with:

mylatexprojects
├── mybibliography.bib
├── mystyle.sty
└── myproject
│   └── main.tex
└── mythesis
    ├── chapters
    │   ├── introduction.tex
    │   ├── methods.tex
    │   ├── mainproof.tex
    │   ├── conclusion.tex
    │   └── appendix.tex
    ├── figures
    │   ├── myInkscapefigure.pdf
    │   ├── myMATLABfigure.png
    │   ├── commutativediagram.tex
    │   ├── longexactsequence.tex
    │   └── trigunitcircle.tex
    └── main
        ├── ETHlogo.pdf
        ├── declaration-originality.pdf
        ├── main.tex
        └── titlepage_abs.tex

Since some of you will be writing a thesis soon, it might make your life easier to have a sample thesis skeleton available. Please note that it is not an official requirement to use this file structure, nor are we claiming it is the best one. In fact, there are most likely better ways to achieve a decent title page. If you still want a working example, you can find it here[1].

At the time of writing, all the .tex files from this link can be compiled[2]. The file mystyle.sty contains some of the most common commands, as well as all the packages and commands required to create graphics in TikZ and Inkscape, as described below. The folder figures contains all the examples from Section 2.1, as well as the sample figures from Sections 2.2 and 2.3.


  1. If the link is dead, if you spot any errors, or if you have some suggestions on how to improve the files or the blog post, please email ana.zegarac@math.ethz.ch. ↩︎

  2. If you're trying to compile directly in Overleaf, some errors with chapter files that contain figures might happen. Compiling the main.tex should work though and the changes you make to the chapter files will be visible. ↩︎

2. Creating graphics

Graphics formats are broadly divided into two categories: vector and raster. Intuitively, vector formats contain information about where each drawn line should be positioned. Raster formats contain information about the colour of individual pixels. Practical consequence of this is that vector images can be scaled without losing their sharpness, whereas raster images become cloudy as we increase their size. Vector formats cannot be used for photographs.

For drawing diagrams, you should try to create your figures in a vector format. If this is not possible and you have to use a raster format, PNG is a good choice. Whatever you do, do not use JPEG for diagrams. Roughly speaking, JPEG compression approximates an image similarly to how you can approximate a function using Fourier series. This does not work well when you have only a few colours, objects with sharp edges, and big contrast, such as in text or graphs. A difference between a PNG image (left) and a JPEG image (right) is shown in the figure below.

Difference between a PNG (left) and a JPEG image (right).

You can insert graphics in your $\mathrm{\LaTeX}$ document by using the graphicx package and the command \includegraphics[width=0.4\textwidth]{filename}, where filename is the path to the graphics file (either absolute or relative to the current folder). If you wish to include caption or a label, the code is

\documentclass{article}
\usepackage{graphicx}
\begin{document}

\begin{figure}[h]
  \centering
  \includegraphics[width=0.4\textwidth]{filename}
  \caption{This is a caption.}
  \label{fig:myfigurelabel}
\end{figure}

\end{document}

It is advisable to always include captions in your figures – often people will look at figures before reading the text, so it is convenient to have a short explanation as a caption. It is also a good idea to refer to every figure at least once in the text.

TIP: If you create your figures in Inkscape (see below), keep the original SVG files in the figures folder. If you generate any plots programmatically (using MATLAB, Mathematica, Python, etc), save the final version of the source code and all raw data required to produce the figure either in the figures folder or in a separate code folder inside your $\mathrm{\LaTeX}$ project.

If you have to make corrections to your figures a few months or weeks after submitting your thesis, having the original SVG files and/or the code to generate the figures will make your life a lot easier. Moreover, if you end up having your work published, the journal might want you to send them the raw data used to generate the figure, as well as the figure itself.

2.1 Creating figures in TikZ

TikZ is a language for producing vector graphics. Essentially, you write some code and out comes a picture. It is a powerful tool, but the learning curve might be little steeper than for your average graphics editor. Below, we list some examples that will hopefully cover the basics of TikZ and that might come in useful in your studies.

2.1.1. Trigonometric unit circle

This example was taken from the excellent TikZ & PGF Manual. In the Manual for Version 3.1.6a, this example can be found (with a lot more details!) in Part I, Section 2, Tutorial: A Picture for Karl’s Students.

Our aim is to draw the following picture.

Trig circle final

We start by learning to draw straight lines. We can draw straight lines between the points $(0,0)$, $(1,1)$, $(2,0)$, $(2.5,1)$ by writing

\documentclass[tikz]{standalone}
\begin{document}

\begin{tikzpicture}
  \draw (0,0) -- (1,1) -- (2,0) -- (2.5,1);
\end{tikzpicture}

\end{document}

Drawing lines

The standalone document class with the option tikz enables us to render only the picture and nothing else. The code for the picture has to be inside the tikzpicture environment. We can modify these commands slightly to draw a coordinate system: we draw two lines, but instead of connecting with a straight line -- the points that define them, we connect them with an arrow ->.

\documentclass[tikz]{standalone}
\begin{document}

\begin{tikzpicture}
  \draw[->] (-1.5,0) -- (1.5,0);
  \draw[->] (0,-1.5) -- (0,1.5);
\end{tikzpicture}

\end{document}

Coordinate system

Using the command \draw (0,0) circle [radius=1cm]; we can add a circle.

\documentclass[tikz]{standalone}
\begin{document}

\begin{tikzpicture}
  \draw[->] (-1.5,0) -- (1.5,0);
  \draw[->] (0,-1.5) -- (0,1.5);
  \draw (0,0) circle [radius=1cm];
\end{tikzpicture}

\end{document}

Circle

Next, we add a grid by using a command \draw[step=.5cm] (-1.4,-1.4) grid (1.4,1.4); This command creates a grid with steps $0.5~\mathrm{cm}$ inside a rectangle with corners $(-1.4,-1.4)$ and $(1.4,1.4)$. To make the lines thinner and lighter, we add attributes gray and very thin. Since we want the grid to be in the background, we add this command at the start of our code.

\documentclass[tikz]{standalone}
\begin{document}

\begin{tikzpicture}
  \draw[step=.5cm,gray,very thin] (-1.4,-1.4) grid (1.4,1.4);
  \draw[->] (-1.5,0) -- (1.5,0);
  \draw[->] (0,-1.5) -- (0,1.5);
  \draw (0,0) circle [radius=1cm];
\end{tikzpicture}

\end{document}

Grid

We now draw and colour the arc at the origin. To draw an arc of $30^\circ$ and radius $3~\mathrm{mm}$ that starts at the point $(3\ \mathrm{mm},0\ \mathrm{mm})$, use the command:

\draw (3mm,0mm) arc [start angle=0, end angle=30, radius=3mm];

To fill objects, we use the command \fill. For example, to fill a triangle determined by the points $(0,0)$, $(1,0)$, $(1,1)$ in orange, we write:

\documentclass[tikz]{standalone}
\begin{document}

\begin{tikzpicture}
  \fill[orange] (0,1) -- (1,0) -- (1,1) -- cycle;
\end{tikzpicture}

\end{document}

Fill demo

The cycle keyword tells TikZ that we want the path to be closed.

In our case, we want both to draw and to fill the drawn object. For this, we use the command \filldraw. We can specify the colour by simply writing its name. It is also possible to specify the colour as a combination of two colours: for $60\%$ orange and $40\%$ white, we write orange!60!white. The code then becomes:

\documentclass[tikz]{standalone}
\begin{document}

\begin{tikzpicture}

  % grid
  \draw[step=.5cm,gray,very thin] (-1.4,-1.4) grid (1.4,1.4);
  \draw[->] (-1.5,0) -- (1.5,0);
  \draw[->] (0,-1.5) -- (0,1.5);
  \draw (0,0) circle [radius=1cm];

  % angle
  \filldraw[fill=orange!10!white, draw=orange] (0,0) -- (3mm,0mm) arc [start angle=0, end angle=30, radius=3mm] -- cycle;

\end{tikzpicture}

\end{document}

Angle

Next, we draw the lines corresponding to the cosine and the sine. For this, we introduce syntax for polar coordinates and we explain how to work with simple intersections. By writing (30:1cm), we specify a point that is at $1~\mathrm{cm}$ away from the origin, at an angle $30^\circ$ from the $x$-axis. The symbol |- between two points gives us a point that lies at the intersection of the horizontal line through the first point and the vertical line through the second point. In other words, if we want the line representing the sine, we use the command

\draw (30:1cm) – (30:1cm |- 0,0); 

As explained above, this draws a straight line between the point (30:1cm) and the point that lies directly below it on the $x$-axis.

Similarly, for the cosine, we use

\draw (0,0) – (30:1cm |- 0,0);

TikZ math engine knows how to compute things like the tangent of a function, so for the line corresponding to the tangent, we use

\draw (1,0) – (1,{tan(30)});

Finally, for the hypotenuse, we use the command

\draw (0,0) – (1,{tan(30)});

We can specify the colour and thickness in square brackets right after the \draw command. With this, the code becomes

\documentclass[tikz]{standalone}
\begin{document}

\begin{tikzpicture}

  % grid
  \draw[step=.5cm,gray,very thin] (-1.4,-1.4) grid (1.4,1.4);
  \draw[->] (-1.5,0) -- (1.5,0);
  \draw[->] (0,-1.5) -- (0,1.5);
  \draw (0,0) circle [radius=1cm];

  % angle
  \filldraw[fill=orange!10!white, draw=orange] (0,0) -- (3mm,0mm) arc [start angle=0, end angle=30, radius=3mm] -- cycle;

  % sin, cos, tan
  \draw[red!80!black,very thick] (30:1cm) -- (30:1cm |- 0,0);
  \draw[blue!80!black,very thick] (0,0) -- (30:1cm |- 0,0);
  \draw[red!50!blue,very thick] (1,0) -- (1,{tan(30)});
  \draw (0,0) -- (1,{tan(30)});

\end{tikzpicture}

\end{document}

sin, cos, tan

To add text, we make use of nodes. The simplest case is that of the angle $\alpha$. To label the angle, we write

\draw (15:2mm) node {(\alpha)};

As before, (15:2mm) specifies a point that is $2~\mathrm{mm}$ away from the origin at an angle $15^\circ.$ The keyword node then inserts a node at this point and the text in the braces is what is displayed. Next, we insert nodes next to the sine and cosine lines by modifying the existing code, as is shown below. Note that this time we create nodes with white fill, so that the labels do not overlap with the grid.

\documentclass[tikz]{standalone}
\begin{document}

\begin{tikzpicture}[scale = 3]

  % grid
  \draw[step=.5cm,gray,very thin] (-1.4,-1.4) grid (1.4,1.4);
  \draw[->] (-1.5,0) -- (1.5,0);
  \draw[->] (0,-1.5) -- (0,1.5);
  \draw (0,0) circle [radius=1cm];

  % angle
  \filldraw[fill=orange!10!white, draw=orange] (0,0) -- (3mm,0mm) arc [start angle=0, end angle=30, radius=3mm] -- cycle;
  \draw (15:2mm) node[orange] {$\alpha$};

  % sin, cos, tan; labels
  \draw[red!80!black,very thick] (30:1cm) -- node[left=1pt,fill=white] {$\sin \alpha$} (30:1cm |- 0,0);
  \draw[blue!80!black,very thick] (0,0) -- node[below=2pt,fill=white] {$\cos \alpha$} (30:1cm |- 0,0);
  \draw[red!50!blue,very thick] (1,0) -- node [right=1pt,fill=white] {$\tan \alpha$}  (1,{tan(30)});
  \draw (0,0) -- (1,{tan(30)});

\end{tikzpicture}

\end{document}

Labels

Here, the option left=1pt moves the label 1pt to the left, and similarly with below and right. Note that we also added [scale=3] in the tikzpicture environment options. This was done in order to have the correct relative size of the labels.

We now add the axis labels in a similar way. This time, we make use of two for-loops. In TikZ, a for-loop starts with a command \foreach, followed by the name of a variable (in our case \x or \y) and the set in which these variables should take values.  The code for the axis labels is then:

\foreach \x in {-1,-0.5,1}
  \draw (\x cm,1pt) – (\x cm,-1pt) node[below=1pt,fill=white] {(\x)};\foreach \y in {-1,-0.5,0.5,1}
  \draw (1pt,\y cm) – (-1pt,\y cm) node[left=1pt,fill=white] {(\y)};

Putting all these commands together gives us the following code.

\documentclass[tikz]{standalone}
\begin{document}

\begin{tikzpicture}[scale = 3]

  % grid
  \draw[step=.5cm,gray,very thin] (-1.4,-1.4) grid (1.4,1.4);
  \draw[->] (-1.5,0) -- (1.5,0);
  \draw[->] (0,-1.5) -- (0,1.5);
  \draw (0,0) circle [radius=1cm];

  % angle
  \filldraw[fill=orange!10!white, draw=orange] (0,0) -- (3mm,0mm) arc [start angle=0, end angle=30, radius=3mm] -- cycle;
  \draw (15:2mm) node[orange] {$\alpha$};

  % sin, cos, tan; labels
  \draw[red!80!black,very thick] (30:1cm) -- node[left=1pt,fill=white] {$\sin \alpha$} (30:1cm |- 0,0);
  \draw[blue!80!black,very thick] (0,0) -- node[below=2pt,fill=white] {$\cos \alpha$} (30:1cm |- 0,0);
  \draw[red!50!blue,very thick] (1,0) -- node [right=1pt,fill=white] {$\tan \alpha$}  (1,{tan(30)});
  \draw (0,0) -- (1,{tan(30)});
  
    % axes labels
  \foreach \x in {-1,-0.5,1}
  \draw (\x cm,1pt) -- (\x cm,-1pt) node[below=1pt,fill=white] {$\x$};
  \foreach \y in {-1,-0.5,0.5,1}
  \draw (1pt,\y cm) -- (-1pt,\y cm) node[left=1pt,fill=white] {$\y$};

\end{tikzpicture}

\end{document}

Trig circle final

2.1.2 Commutative diagrams

While the main purpose of the first example was to get you comfortable with some basics of TikZ, this and the next example are something that you might eventually need in your work.

In this section, we go draw a simple commutative diagram with tikzcd, a TikZ library specialised for this task. For this to work, we need \usepackage{tikz-cd} in the preamble and the tikzcd environment in the body.

Let us say we would like to make a diagram as shown below.

Coordinate system

Just like when using tabular environment, in tikzcd, the character & is a column separator and \\ is a row separator. We begin by specifying what our nodes should be:

\documentclass[tikz]{standalone}
\usepackage{tikz-cd}
\begin{document}

\begin{tikzcd}
  A & B  \\
    & C
\end{tikzcd}

\end{document}

Coordinate system

Next, we insert arrows using the \arrow command. The arrow will start at the node next to which we write the command. Its direction can be specified by a string of characters consisting of l, r, u, d, meaning left, right, up, down, respectively. We thus write

\documentclass[tikz]{standalone}
\usepackage{tikz-cd}
\begin{document}

\begin{tikzcd}
A \arrow[r] \arrow[dr] & B \arrow[d] \\
                       & C
\end{tikzcd}

\end{document}

Coordinate system

To insert arrow labels, we add them as parameters in quotation marks.

\documentclass[tikz]{standalone}
\usepackage{tikz-cd}
\begin{document}

\begin{tikzcd}
  A \arrow[r, "\phi"] \arrow[dr, "\psi"] & B \arrow[d, "\pi"] \\
                                         & C
\end{tikzcd}

\end{document}

Coordinate system

The $\psi$ label would perhaps fit better at the other side of the arrow, as there is more space there. To achieve this, we add the option swap to the arrow in question:

\documentclass[tikz]{standalone}
\usepackage{tikz-cd}
\begin{document}

\begin{tikzcd}
  A \arrow[r, "\phi"] \arrow[dr, "\psi" swap] & B \arrow[d, "\pi"] \\
                                              & C
\end{tikzcd}

\end{document}

Coordinate system

2.1.3 Long exact sequences

We now explain how to draw a long exact sequence with a line break, as shown in the following figure.

Coordinate system

This example was taken from the TikZ-cd manual. You can find it in Section 3.2. We can apply the things we learned in the previous example to draw everything apart from the snake arrow. The code for this is:

\documentclass[tikz]{standalone}
\usepackage{tikz-cd}
\begin{document}

\begin{tikzcd}
  A \arrow[r]
  & B \arrow[r]
  & C \\
  D \arrow[r]
  & E \arrow[r]
  & F
\end{tikzcd}

\end{document}

Coordinate system

Our strategy for the snake arrow is to specify a point (Z) right between the nodes $B$ and $E$ and to draw an arrow first going to the right of $C$, then vertically down to the height of (Z), then through (Z) all the way to left of $D$, then vertically down and finally ending at $D$.

We specify the point (Z) by creating an invisible (or phantom) arrow from $B$ to $E$ and taking its middle. This is done by writing

\arrow[d, phantom, “”{coordinate, name=Z}]

next to the existing arrow starting at $B$, as the following code shows.

\documentclass[tikz]{standalone}
\usepackage{tikz-cd}
\begin{document}

\begin{tikzcd}
  A \arrow[r]
  & B \arrow[r] \arrow[d, ""{coordinate, name=Z}, phantom]
  & C \\
  D \arrow[r]
  & E \arrow[r]
  & F
\end{tikzcd}

\end{document}

Here, the empty quotes "" mean that the label is empty and instead the stuff in braces creates a coordinate with name (Z). This code generates the same picture as the earlier code.

Now the command for the snake arrow starting at $C$ is

C & \arrow[dll, rounded corners,
  to path = {
    -- ([xshift=2ex]\tikztostart.east)
    |- (Z)
    -| ([xshift=-2ex]\tikztotarget.west)
    -- (\tikztotarget)
  }] \\

Let us dissect what this command does. Firstly, dll specifies that the target is down one cell and two cells to the left of $C$. Next, as one might expect, rounded corners makes the corners round. The command to path={…} specifies the geometry of the arrow. The arrow starts at $C$ and the first (nontrivial) line in to path determines the next point that the arrow will reach in a straight line. In this case, we want the next point to be 2ex to the right of the starting point. The command \tikztostart returns the starting point. More precisely, it returns the coordinates of the centre of the starting cell. Since the arrow starts on the right side of it, the precise coordinates of the starting point of the arrow can be obtained by writing \tikztostart.east. To shift this coordinate to the right by 2ex, we write ([xshift=2ex]\tikztostart.east). It might be helpful to keep the following figure in mind.

les-2-explanation

The command A |- B draws first a vertical line starting at the point A and then a horizontal line ending at point B. Thus

 ([xshift=2ex]\tikztostart.east) |- (Z)

draws a line starting at ([xshift=2ex]\tikztostart.east), going vertically down until it reaches the height of (Z), then going horizontally until (Z).

Similarly,

(Z) -| ([xshift=-2ex]\tikztotarget.west)

draws first a horizontal line from (Z) to the point with the same $x$ coordinate as ([xshift=-2ex]\tikztotarget.west) and draws a vertical line from this coordinate ([xshift=-2ex]\tikztotarget.west).

Finally,

([xshift=-2ex]\tikztotarget.west – (\tikztotarget)

connects the last two points.

The full code is thus:

\documentclass[crop,tikz]{standalone}
\usepackage{tikz-cd}
\begin{document}

\begin{tikzcd}
  A \arrow[r]
  & B \arrow[r] \arrow[d, ""{coordinate, name=Z}, phantom]
  & C \arrow[dll, rounded corners,
  to path = {
    -- ([xshift=2ex]\tikztostart.east)
    |- (Z)
    -| ([xshift=-2ex]\tikztotarget.west)
    -- (\tikztotarget)
  }] \\
  D \arrow[r]
  & E \arrow[r]
  & F
\end{tikzcd}

\end{document}

Coordinate system

2.2. Importing figures from Inkscape

Inkscape is a free and open source vector graphics editor. It is useful when you want to draw somewhat complex pictures relatively quickly. Inkscape also supports $\mathrm{\LaTeX}$ math mode: whatever you write inside dollar signs can be rendered as if it is inline math. For all this to work, you have to save your figure as a PDF and in the following window select the “Omit text in PDF and create LaTeX file” option, as shown in the figure below.

Inkscape export settings for use in a LaTeX document.

In your mystyle.sty file (or preamble if you are not using the style file) you have to define the following command:

\newcommand{\incfig}[2] {
  \def\svgwidth{#1\columnwidth}
  \import{../figures/}{#2.pdf_tex}
}

Note: this command assumes your folder structure is as described above (in other words, that the folder with your main file and the folder with the figures at the same level). For other project structures, you have to modify the ../figures part of the import command above.

Then you can insert the figure in your document by writing

\incfig{0.4}{myfigure}

Here, 0.4 means that the width of the figure will be 0.4\columnwidth. Below is a sample image created in Inkscape and then imported in a $\mathrm{\LaTeX}$ document.

Sample image created in Inkscape

2.3. Importing figures from MATLAB

If you’re exporting your files from a different program (for example MATLAB or Mathematica) with the aim of using them in your $\mathrm{\LaTeX}$ document, we found that the best way is to render your files in a higher resolution (at least 300 dpi) and save them as a PNG. Whatever you do, do not use JPEG for graphs, diagrams, or if you have text in your image.

For MATLAB, you can use the following command to save your figure in 300 dpi resolution. Your figure has to be visible inside MATLAB at the time you run this command.

print(gcf,'myMATLABfigure.png','-dpng','-r300');
A sample figure created in MATLAB using the built-in peaks function and then exported using the command above.

For Mathematica, if you name your graphics object g, then you can run the following command to export it in 300 dpi:

Export["myMathematicafigure.png", g, ImageResolution -> 300]

3. Other tips

3.1 Naming labels

It is convenient to name labels systematically. For example, if you are writing about Pythagoras’ theorem and want to label the well-known equation, then rather than using \label{pyhtagoras} for it, it is better to use \label{eq:pythagoras}. A little later maybe you realise you want to introduce this in a theorem, which you also want to label. Using \label{thm:pythagoras} for the later removes ambiguity between the two. Moreover in your longer works it can happen that you want to reference a result by Smith that you mentioned few pages earlier, but you can’t remember if you stated it as a proposition or a lemma. In Overleaf (and many other editors), simply writing \ref{smi will give you suggestions based on existing labels. If you then see prop:smith2008 in suggestions, you will immediately know that it was indeed a proposition and you won’t have to scroll through half of the file to check.

Tip: To avoid a possible line break between the name of the element you are referring to and its number, you can use ~. For example, instead of writing Lemma \ref{lma:poincare}, you can write Lemma~\ref{lma:poincare}.

3.2. Finding symbols

If you find yourself in a situation where you want to write a symbol in $\mathrm{\LaTeX}$, but cannot remember the command, https://detexify.kirelabs.org/ might be able to help you. It is a website where you can draw the symbol you have in mind, and it will show you all commands that match your drawing.