# What do you use to embed Julia code in LaTeX?

**URL:** <https://discourse.julialang.org/t/what-do-you-use-to-embed-julia-code-in-latex/23992>\
**Category:** General Usage\
**Created:** [May 8, 2019, 10:28am UTC](https://discourse.julialang.org/t/what-do-you-use-to-embed-julia-code-in-latex/23992 "2019-05-08T10:28:08Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [May 8, 2019, 10:51am UTC](https://discourse.julialang.org/t/what-do-you-use-to-embed-julia-code-in-latex/23992/2 "2019-05-08T10:51:21Z")

</div>

For julia in latex I use minted.  
To run julia in presentations I use the “export to reveal.js slides” option in Jupyter

Here is a short wiki I created for my coworkers to include julia in latex

# Minted

It is possible to include julia code using the package minted [GitHub - gpoore/minted: minted is a LaTeX package that provides syntax highlighting using the Pygments library. Highlighted source code can be customized using fancyvrb.](https://github.com/gpoore/minted)

## Prerequisites

pygmentize is required, if it is not installed, try running _sudo pip install pygments_

Get latest version of _minted.sty_ from the github repo above. Put it in you texlive package folder or in the current working directory. Minted has other prerequisites, but those should be installed already.

## A small example

- \begin{minted}[breaklines,escapeinside=||,mathescape=true, linenos, numbersep=3pt, gobble=2, frame=lines, fontsize=\small, framesep=2mm]{julia}
  - Your awesome julia code here\end{minted}

[minted.tex](https://www.control.lth.se/media/Staff/FredrikBaggeCarlson/minted.tex) [minted.pdf](https://www.control.lth.se/media/Staff/FredrikBaggeCarlson/minted.pdf)

## Inclusion of unicode characters

With julia, one has the option of including most unicode characters in the code. For a copy-paste-kind of strategy to work, I have found the following two packages useful

\usepackage[mathletters]{ucs} \usepackage[utf8x]{inputenc}

With these packages, unicode characters in the input are handled quite well. At least if one builds with latexmk and pdflatex.

With luatex, use the following instead \usepackage[T1]{fontenc} \usepackage{unicode-math}

See [https://tex.stackexchange.com/questions/251446/problem-with-math-symbols-unicode-math](https://tex.stackexchange.com/questions/251446/problem-with-math-symbols-unicode-math) for info regarding setting a math font. The following selects the font that is default in Atom

\usepackage{fontspec}\setmonofont{[DejaVu](https://wiki.control.lth.se/DejaVu) Sans Mono}[Scale=0.8]

Note, there might be some conflicts between unicode-math and the department fonts. If you get errors, try removing all other font choices, such as schoolbook, newtxtext, newtxmath,inconsolata,fourier, and see if the erros go away.

## Issues

### Beamer

Frames must be declared fragile for minted to work

\begin{frame}[fragile]

### Other issues

Minted has issues if the build output is stored in a subdirectory and not in the working directory, use \usepackage[outputdir=build]{minted}

If _pygments_ is installed but _pygmentize_ can not be found, reinstall _pygments_ .

---

_[View the full topic](https://discourse.julialang.org/t/what-do-you-use-to-embed-julia-code-in-latex/23992)._
