This repo explains my setup for producing PDF documents which include Julia code. There are a lot of specific choices described here, but you can mix-and-match according to your preferences.
- Install TeX. I use TinyTeX, but large installations like MacTeX and MikTeX are easier.
- (Optional) Install my LaTeX class and sty files (to get the styling you see in the document in this repo).
- (Optional) Install the Atom editor with nteract's Hydrogen package and the
atom-latex
package (maintained by ashthespy). Go into the settings set a mapping for the Julia kernel (Atom > Preferences > Packages > Hydrogen > Settings > paste{ "julia": "latex" }
into the Language Mapping section). - Clone this repo and open it in Atom. Compile
data1010.tex
for an example.
- Select some Julia code and in your editor do shift-enter to run the code directly in your TeX document.
- Get syntax-highlighted code in your PDF output, thanks to the Pygments package. Inline Julia code uses
\jlverb{}
, while code blocks are obtained using thejuliablock
environment (\begin{juliablock}...\end{juliablock}
). - Incorporate Julia output into your document using
\jl{}
for inline stuff. If you want a block of Julia code to run for purposes of producing said output, use the environmentjuliablockc
instead ofjuliablock
. If you want code to run but not display, use thejuliahidden
environment. You'll need to run pythontex for this feature; this entails running (for example)pythontex3 data1010.pytxcode
between TeX runs whenever you update code. Alternatively, you can try thelua
option of the packagejuliatex.sty
, which uses Julia's and Lua's foreign function interfaces to call Julia from Lua during the LuaTeX run. This might require some configuration, because you'll need to point Lua to your Julia installation injuliatex.sty
. - If you want to produce a standalone
.jl
or.jmd
file to run from the command line withjulia
or Weave, you can run the scriptmakejmd.jl
. This script uses files which are written during the TeX run, so you do have to compile first.