Skip to content

# Wookai/paper-tips-and-tricks

Best practice and tips & tricks to write scientific papers in LaTeX, with figures generated in Python or Matlab.
Python
Wookai Merge pull request #9 from aaronlauterer/Fix_figure_rasterized_exampl…
…e_link

Fix figure_rasterized_example link
Latest commit 2f6ee98 May 7, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
src/python
.gitignore
LICENSE
README.md

# Tips and Tricks for Writing Scientific Papers

## What is this?

This repository contains a list of tools, best practices, tips and other guidelines we found useful/important when writing scientific papers. Some are a matter of style (we tend to follow the guidelines of the Chicago Manual of Style), and we are well aware that other people prefer to do things differently, but we list them anyway to have a consistent guide. Feel free to adapt, change, ignore, or even challenge everything we write!

# Typesetting your paper

Typesetting is the composition of text by means of arranging the types, i.e., letters and symbols. It is mostly a question of a aesthetics, but beautiful typography makes documents easier and more pleasant to read, helping the reader to get to the message.

We list below some typesetting tips and tools to help you when composing your documents. Some tips are specific to LaTeX, but others apply regardless of what you are using.

## One sentence per line

When writing LaTeX documents, put one sentence per line in your source file. Write:

This is my first sentence.
This is the second one.


and not:

This is my first sentence. This is the second one.


The main reason for this is source control and collaboration: when looking at the changes of a commit, it is much easier to identify what sentence was changed if they are each on their separate line. Your coworkers will thus be able to see the changes more easily.

Another benefit is that you will be able to better identify errors when only given a line number by our LaTeX compiler.

## Capitalization

We will refer below to two types of capitalization:

• sentence format : The title of the nice book
• title format: The Title of the Nice Book

Use title format for all section, subsection, etc. titles. In order to help you capitalize the right words, there's a handy website: titlecapitalization.com.

## Tables

(complete example)

booktabs can help you produce clean and nice-looking tables.

\usepackage{booktabs}
% --
\begin{table}
\centering
\begin{tabular}{lcc}
\toprule
& \multicolumn{2}{c}{Data} \\ \cmidrule(lr){2-3}
Name & Column 1 & Another column \\
\midrule
Some data & 10 & 95 \\
Other data & 30 & 49 \\
\addlinespace
Different stuff & 99 & 12 \\
\bottomrule
\end{tabular}
\caption{My caption.}
\label{tab-label}
\end{table}


In general, avoid using vertical lines in your tables. Instead, if you want to group columns, do it in the headers using \cmidrule. You can also replace horizontal lines with spacing, using \addlinespace.

Column heads should use sentence-format capitalization (see http://www.chicagomanualofstyle.org/15/ch13/ch13_sec019.html).

You can find more advice on table formatting here: http://www.inf.ethz.ch/personal/markusp/teaching/guides/guide-tables.pdf. Here is a nice GIF that illustrates some of these rules:

## Number formatting

(complete example)

Use the siunitx package to format all numbers, currencies, units, etc:

\usepackage{siunitx}
% ---

ax.set_axisbelow(True)

plt.grid()
plt.tight_layout()

if args.save:
pu.save_fig(fig, args.save)
else:
plt.show()

if __name__ == '__main__':
parser = argparse.ArgumentParser()

parser.add_argument('-s', '--save')

args = parser.parse_args()
main(args)


## Figures format

We recommend saving all figures in the EPS format. This way, you can use both latex and pdflatex to generate your documents, and enjoy beautiful vector graphics and texts.

As of September 2015, on Mac OS X and with up-to-date versions of Python, Matplotlib and TeX Live, there is a loss of quality when printing figures that were directly saved as PDF from Matplotlib. It becomes clearly when printed on real paper; try it out for yourself. This is another reason to prefer saving Matplotlib-generated pictures in EPS. If you really want to keep only a PDF version of the figure, use the epspdf command line tool---the resulting PDF will be better than that directly produced by Matplotlib.

For completeness, note that there is another Matplotlib backend, PGF, that produces slightly superior results. However, as of September 2015, the resulting PDFs are twice as heavy as those obtained with the default backend and epspdf.

Matplotlib, even when using tight layout features, adds at times too much white space in the margins. A nifty command-line tool to crop a PDF to its tightest bounding box pdfcrop.

## Rasterize parts of the figure

If you have many data points in your plot, the resulting EPS file might be very big. You could save your figure as a PNG file, but this would result in blurry texts. The solution is to rasterize parts of your figure, i.e., to tell matplotlib that the data points have to be rendered as a bitmap in the EPS file, while the rest is in vector format.

You can pass the rasterized=True keyword to most plotting fuctions in matplotlib. You can also use different layers using the zorder and tell matplotlib to rasterize all the layers below a given zorder using the set_rasterization_zorder() method of the axis. See figure_rasterized_example.py and http://matplotlib.org/examples/misc/rasterization_demo.html for examples of rasterization.

# Useful resources

You can’t perform that action at this time.