Commit a26db80c authored by Ingo Heimbach's avatar Ingo Heimbach

Code blocks are formatted with `minted`; added a XeLaTeX style file

parent 92e9f2a3
......@@ -17,7 +17,7 @@ pip install git+https://iffgit.fz-juelich.de/doc-utils/doc-utils
After installing you can use the extended rst writers `rst2latex-extended` and `rst2html-extended` that are compatible
with the standard versions but offer additional features:
- Code blocks are formatted with the `listings` package (LaTeX only)
- Code blocks are formatted with the `minted` package (LaTeX only)
- Images can be embedded into the generated document (`embedded-image` directive, HTML only; for LaTeX this is already
the default behavior)
- Support for TikZ images by `tikz` and `tikz-figure` directives. TikZ code can be loaded from an external file or
......@@ -31,4 +31,5 @@ with the standard versions but offer additional features:
`--syntax-highlight=short` option with `rst2html` is recommended but long class names are also included in the this
CSS file
- `styles/rst2latex_fzj.sty`: Style with fzj colors and a custom title page
- `styles/rst2luatex_fzj.sty`: Style with fzj colors and a custom title page for use with LuaTex / LuaLaTeX
- `utils/Makefile`: Example Makefile for generating PDFs and HTML pages from Markdown and reStructuredText documents
......@@ -9,10 +9,8 @@ class CodeBlock(Directive):
option_spec = {}
has_content = True
rstlang_to_listingslang = {"pytb": "{}", "text": "{}"}
def run(self):
language = self.rstlang_to_listingslang.get(self.arguments[0], self.arguments[0])
language = self.arguments[0]
content = u"\n".join(self.content)
latex = u"\\begin{{lstlisting}}[language={}]\n{}\n\\end{{lstlisting}}".format(language, content)
latex = u"\\begin{{minted}}{{{}}}\n{}\n\\end{{minted}}".format(language, content)
return [nodes.raw("", latex, format="latex")]
......@@ -6,44 +6,30 @@
\PassOptionsToPackage{warn}{textcomp}
\usepackage{lmodern}
\usepackage{amssymb}
\usepackage{listings}
\usepackage{minted}
\usepackage{xcolor}
\usepackage{iflang}
\usepackage{tikz}
\usetikzlibrary{calc}
\definecolor{fzjblue}{RGB}{2,61,107}
\definecolor{mintedbg}{RGB}{252, 252, 255}
\renewcommand{\textbf}[1]{{\bfseries\color{fzjblue}#1}}
% Based on the GitHub theme
\lstset{
basicstyle=\ttfamily\color{black}\footnotesize,
keywordstyle=\color[RGB]{215, 58, 73},
emphstyle=\color[RGB]{0, 92, 197},
commentstyle=\color[RGB]{106, 115, 125},
stringstyle=\color[RGB]{0, 114, 0},
numbers=left,
numberstyle=\tiny\color{gray},
stepnumber=1,
tabsize=2,
breaklines,
breakatwhitespace,
showspaces=false,
showstringspaces=false,
backgroundcolor=\color[RGB]{252, 252, 255},
\setminted{
bgcolor=mintedbg,
breaklines=true,
fontsize=\footnotesize,
frame=single,
language=bash
linenos=true,
python3=true,
style=friendly,
tabsize=2
}
\lstset{literate=%
{Ö}{{\"O}}1
{Ä}{{\"A}}1
{Ü}{{\"U}}1
{ß}{{\ss}}1
{ü}{{\"u}}1
{ä}{{\"a}}1
{ö}{{\"o}}1
{~}{{\textasciitilde}}1
% Set minted line number style
\renewcommand{\theFancyVerbLine}{%
\sffamily\textcolor{gray}{\scriptsize\arabic{FancyVerbLine}}
}
\renewcommand{\maketitle}{
......
% Author: Ingo Heimbach
% Contact: i.heimbach@fz-juelich.de
%
% Style for use with Docutils/rst2latex/lualatex.
\PassOptionsToPackage{warn}{textcomp}
\usepackage{fontspec}
\usepackage{lmodern}
\usepackage{amssymb}
\usepackage{minted}
\usepackage{ucharclasses}
\usepackage{xcolor}
\usepackage{iflang}
\usepackage{tikz}
\usetikzlibrary{calc}
\newfontfamily\DejaVuSans{DejaVuSans}
\newfontfamily\DejaVuSansMono{DejaVuSansMono}
% define a fallback font for symbols (like emoticons) that are not available in DejaVu Sans Mono
% solution taken from https://tex.stackexchange.com/a/32268
\setTransitionsForMathematics{%
\makeatletter\let\curfamily\f@family\let\curshape\f@shape\let\curseries\f@series\makeatother\DejaVuSans%
}{%
\fontfamily{\curfamily}\fontshape{\curshape}\fontseries{\curseries}\selectfont%
}
\setTransitionsForSymbols{%
\makeatletter\let\curfamily\f@family\let\curshape\f@shape\let\curseries\f@series\makeatother\DejaVuSans%
}{%
\fontfamily{\curfamily}\fontshape{\curshape}\fontseries{\curseries}\selectfont%
}
\definecolor{fzjblue}{RGB}{2,61,107}
\definecolor{mintedbg}{RGB}{252, 252, 255}
\renewcommand{\textbf}[1]{{\bfseries\color{fzjblue}#1}}
\setminted{
bgcolor=mintedbg,
breaklines=true,
formatcom=\DejaVuSansMono,
fontsize=\footnotesize,
frame=single,
linenos=true,
python3=true,
style=friendly,
tabsize=2
}
% Set minted line number style
\renewcommand{\theFancyVerbLine}{%
\sffamily\textcolor{gray}{\scriptsize\arabic{FancyVerbLine}}
}
\renewcommand{\maketitle}{
\providecommand{\documenttype}{\IfLanguageName{ngerman}{Technische Dokumentation}{Technical Documentation}}%
\begin{titlepage}
\sffamily
\makeatletter
\begin{tikzpicture}[remember picture, overlay]
\node[anchor=north] at ($ (current page.center) + (0, 0.5\textheight) $) {%
\LARGE\scshape%
\parbox{\textwidth}{\centering\documenttype}%
};%
\fill[ultra thick, fill=fzjblue] ($ (current page.north west) - (0, 0.25\paperheight) $) rectangle +(\paperwidth, -0.1\paperheight);
\node at ($ (current page.north) - (0, 0.3\paperheight) $) {%
\LARGE\bfseries%
\parbox{\textwidth}{\centering \color{white}\@title}
};%
\node at ($ (current page.center) + (0, 0.05\textheight) $) {%
\Large%
\parbox{\textwidth}{\centering \@author}
};
\node at ($ (current page.center) + (0, -0.05\textheight) $) {%
\large%
\ifthenelse{\equal{\@date}{}} {
\today
}{
\@date
}
};
\node[anchor=south] at ($ (current page.center) + (0, -0.5\textheight) $) {%
\parbox{\textwidth}{\centering
Forschungszentrum Jülich GmbH \\[1ex]
Peter Grünberg Institut / Jülich Centre for Neutron Science \\
Technische Administration \\
(PGI/JCNS-TA)
}%
};%
\node[anchor=south west, inner sep=0, outer sep=0] at ($ (current page.south west) + (0.05\paperwidth, 1.0631) $) {%
\sffamily\color{fzjblue}\IfLanguageName{ngerman}{Mitglied der Helmholtz-Gemeinschaft}{Member of the Helmholtz Association}%
};
\node[anchor=south east, inner sep=0, outer sep=0] at (current page.south east) {
\includegraphics[height=0.1769\paperwidth]{fz_logo_schutzzone}%
};%
\end{tikzpicture}
\makeatother
\end{titlepage}
}
......@@ -23,21 +23,21 @@ pdf: $(PDFFILES)
cp "$${TEMP_HTML_DIR}/$@" ./ && \
rm -rf "$${TEMP_HTML_DIR}"
%.pdf: %.rst .rst2latex.sty .fz_logo_schutzzone.pdf
%.pdf: %.rst .rst2xetex.sty .fz_logo_schutzzone.pdf
TEX_FILENAME="$$(basename $< .rst).tex" && \
TEMP_TEX_DIR="$$(mktemp -d)" && \
cp $< .rst2latex.sty "$${TEMP_TEX_DIR}/" && \
cp $< .rst2xetex.sty "$${TEMP_TEX_DIR}/" && \
cp .fz_logo_schutzzone.pdf "$${TEMP_TEX_DIR}/fz_logo_schutzzone.pdf" && \
pushd "$${TEMP_TEX_DIR}" && \
$(RST2LATEX) --documentclass=scrartcl \
--hyperref-options=hidelinks \
--stylesheet=.rst2latex.sty \
--stylesheet=.rst2xetex.sty \
--stylesheet-dirs="$$(pwd)" \
--no-section-numbering \
--use-latex-docinfo \
--latex-preamble="\usepackage[ngerman]{babel}" \
$< "$${TEX_FILENAME}" && \
latexmk -pdf -halt-on-error "$${TEX_FILENAME}" && \
latexmk -xelatex -halt-on-error -shell-escape "$${TEX_FILENAME}" && \
popd && \
mv "$${TEMP_TEX_DIR}/$@" ./ && \
rm -rf "$${TEMP_TEX_DIR}"
......@@ -45,8 +45,8 @@ pdf: $(PDFFILES)
%.rst: %.md
$(PANDOC) --from=markdown --to=rst -o $@ $<
.rst2latex.sty:
curl -o $@ -L https://iffgit.fz-juelich.de/doc-utils/doc-utils/raw/master/styles/rst2latex_fzj.sty
.rst2xetex.sty:
curl -o $@ -L https://iffgit.fz-juelich.de/doc-utils/doc-utils/raw/master/styles/rst2xetex_fzj.sty
.rst2html.css:
curl -o $@ -L https://iffgit.fz-juelich.de/doc-utils/doc-utils/raw/master/styles/rst2html_githublike_fzj.css
......@@ -55,6 +55,6 @@ pdf: $(PDFFILES)
curl -o $@ -L https://iffwww.iff.kfa-juelich.de/pub/downloads/fz_logo/fz_logo_schutzzone.pdf
clean:
rm -f *.html *.pdf .rst2latex.sty .rst2html.css .fz_logo_schutzzone.pdf $(patsubst %.md,%.rst,$(MDFILES))
rm -f *.html *.pdf .rst2xetex.sty .rst2html.css .fz_logo_schutzzone.pdf $(patsubst %.md,%.rst,$(MDFILES))
.PHONY: all clean html pdf
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment