Files
latex/docs/parts/reference/extras.tex
Janis Hutz cb173908b4
All checks were successful
Build docs / build_docs (push) Successful in 47s
Build helpers / build_helpers (push) Successful in 5s
Add better code support
2026-01-04 11:58:10 +01:00

68 lines
3.0 KiB
TeX

\newpage
\subsection{Extras}
\subsubsection{BibTeX}
\textit{Included in \texttt{recommended} and up}
Use \verb|\setupBiber|\{\textit{/path/to/your/bib/sources.bib file}\} in the preamble to prepare, then use \verb|\printbib| to print your bibliography.
To add more sources, simply use bibter's built-in macro \verb|\addbibresource|\textit{\{filepath\}}, which will load your \texttt{.bib} file.
You need to use that inside the preamble as well.
% ────────────────────────────────────────────────────────────────────
\subsubsection{Glossary}
\textit{Included in \texttt{recommended} and up}
Use \verb|\setupGlossary| in the preamble to prepare, then use the normal glossary commands to add entries to the glossary. When you want to print it, use \verb|\printGlossary|.
% ────────────────────────────────────────────────────────────────────
\subsubsection{Minted}
\textit{Included in \texttt{full}}
Be sure to enable \texttt{-shell-escape} for your compiler
\textit{(Note: Some newer versions of LaTeX do no longer require this and it is better to keep it turned off for security reasons, if it works without)}!
When \texttt{minted} is available via these helpers, you will also have access to the \texttt{code} environment:
\begin{minted}{latex}
\begin{code}{language}
// Code goes here
\end{code}
\end{minted}
This is nothing different than a wrapper for a minted environment with a box drawn around it.
Example (in python):
\begin{code}{python}
def hello_world():
print("hello world!")
\end{code}
If instead, you want to have the code in separate source files, you can use (relative to root file)
\begin{minted}{latex}
\inputcode{<language>}{path/to/source/file}
\end{minted}
The helpers also provide a wrapper for this, which also prints the filename:
\begin{minted}{latex}
\inputcodewithfilename{<language>}{<base dir>}{<file>}
\end{minted}
where the base dir is relative to the root file of the latex document and is not displayed (and should end in \texttt{/}), and the file is relative to the base dir and is displayed.
Example (assume file at \texttt{./code/lib/demo.py} and you want the file name to be \texttt{lib/demo.py}):
\begin{minted}{latex}
\inputcodewithfilename{python}{code/}{lib/demo.py}
\end{minted}
You may of course leave the base dir argument empty as well.
\fhlc{Cyan}{Inline Code}
If you want to print code inline, use \verb|\inlinecode|\textit{\{string\}}, which renders to \inlinecode{code}.
\textit{Caveat: This is not using the \texttt{verbatim} environment due to various limitations of that environment and instead is simply using} \verb|\texttt{}|, so you cannot use this to print \LaTeX-commands
Alternatively, to get code highlighting, you can use \verb|\mint{<language>}|\texttt{|code|}