Jinja2 templates for latex - tutorials - latex

I was wondering if someone can point me to the tutorials on how to create custom Jinja2 templates for LaTeX, so that I can use it in with nbconvert to convert Jupyter notebook into LaTeX?

Unfortunately that is highly undocumented. I would suggest asking on the mailing list or directly open an issue on GitHub (jupyter/nbconvert repo)
The normal template informations you find will work with one difference that you need to replace the template extension from .tpl to .tplxand replace the jinja delimiters: {% to ((* for blocks , {{ to ((( for variable interpolations and {# to ((= for comments + all the symetric closing markers. The reasoning is that latex uses { heavily and you want to avoid conflict.
Otherwise there is close to no difference between latex and non-latex templates.

I found this tutorial from the IPython/Jupyter Workshop at the NGCM Summer Academy (official jupyter github).

Related

Get Latex structure of a document

I'm looking for a way to get a generic structure (as JSON) for a latex document:
Directly from texlive
As a Python module (For example: https://pylatexenc.readthedocs.io/en/latest/latexwalker/)
As a Node module (For example: https://www.npmjs.com/package/latex-ast-parser)
Is there a preferred way to do that to be sure to support most of things of Latex?
Thanks for your help,
Thierry

Converting code listings from mediawiki to latex using pandoc

Is there an easy way to say pandoc converter I wish to replace all my source codes in mediawiki article convert to an lstlisting environment on its Latex output?
At this moment, all my <source lang="c"> some code... </source> environments are converted into something like this
\begin{Shaded}\begin{Highlighting}[]
\NormalTok{ some code \textless{}\textless{} }\DecValTok{1}\NormalTok{ \CommentTok{// set... \end{Highlighting}
\end{Shaded}
Not only the code is completely unreadable but also my Latex distribution is not able to translate the code and is missing probably some packages.
I wish to have simply \begin{lstlisting} some code \end{lstlisting} at the output with no additional changes to the code itself.
And I don't speak Haskell, believing there should be an easier way...
Solution was very simple. There is a --listings command line option solving this problem as Sam Carter pointed out.

usepackage and making macros in ipython notebook

How can user macros and packages be included in the latex rendered in markdown cells in ipython?
e.g.:
\usepackage{amssymb}
\newcommand{kms}{\ensuremath{\mathrm{km~s}^{-1}}
It is possible to define macros in cells with markdown. Just put the \newcommand between $'s:
$\newcommand{kms}{{\mathrm{km~s}^{-1}}}$
(Note that I removed the \ensuremath command, as it is not accessible.)
In any following statement (in the whole notebook) you can call the macro (in a markdown cell only, of course):
$\kms$
I do not know a way to include extra packages :( If you ever learn how, I would also encourage you to use the siuntx package to format units.
The Html notebook use mathjax to render LaTeX, I suggest reading its doc to know wether it is possible and how.

Is there a good and fast way of printing (on paper) code's syntax highlight?

I'm going to a farm. I think there are no computers there, and my laptop is broken. I want to print out the code of some of my projects on A4 paper so I can review it while I'm there. It would be nice if it was printed with syntax highlighting.
Editors: Vim, Notepad++
Code: Html, CSS, Javascript
enscript
pygmentize
In emacs use ps-print-buffer-with-faces. There is also ps-print-region-with-faces for those occasions when you only want part of a file...
Use M-x <command> to invoke commands by name. Use C-h f <command> for help on a command and also to learn what (if any) keybinding it has.
a2ps tool produces nice PostScript files for program listing printing.
Vim has :TOhtml command which produces HTML with current open file highlighted according to Vim syntax coloring. GVim has Syntax -> Convert to HTML menu for this.
If you use LaTeX, look at listings package (pdf documentation at CTAN). It's a very good solution for including your code in documentation/presentation.
All these tools support syntax of many programming (and non-programming) languages.
Editplus prints with syntax highlighting intact

LaTeX help with href

I am trying to create a hyperlink using LaTeX. When I use the command pdflatex to compile the file, I get an error.
The relevant lines of the document are:
\documentclass[12pt]{article}
\usepackage{hyperref}
\begin{document}
...
\href{http://www.cs.utah.edu/dept/old/texinfo/as/gprof_toc.html}{gprof}
pdflatex created a file called missfont.log, which contains this:
mktextfm pzdr
What am I doing wrong?
Do you have the pzdr font installed? If you're on Debian or Ubuntu, try installing the texlive-fonts-recommended package.
Does the hyperref package purport to make hyperlinks to arbitrary web pages? I thought it was just for intra-document links (which it does automatically). I would do
\usepackage{url}
and
\url{http://foo.com}
to format a URL in your document.
ADDED: Thanks Will, I didn't know that about href. But if you're creating a document that's mainly targeting paper as the intended medium, I think the url package for formatting URLs is the way to go. But if you think the href package subsumes the url package, I'd love to be set straight on that.

Resources