Add better code support
This commit is contained in:
29
dist/full.tex
vendored
29
dist/full.tex
vendored
@@ -1085,8 +1085,11 @@
|
|||||||
\usepackage{minted}
|
\usepackage{minted}
|
||||||
\usepackage{fancyvrb}
|
\usepackage{fancyvrb}
|
||||||
|
|
||||||
|
% Args: Code.
|
||||||
|
% Alternative: Use \mint{<language>}|code|
|
||||||
\newcommand{\inlinecode}[1]{\shade{gray}{\texttt{#1}}}
|
\newcommand{\inlinecode}[1]{\shade{gray}{\texttt{#1}}}
|
||||||
|
|
||||||
|
% Args: Language, Code
|
||||||
\newenvironment{code}[1]{
|
\newenvironment{code}[1]{
|
||||||
\VerbatimEnvironment
|
\VerbatimEnvironment
|
||||||
\begin{minted}[
|
\begin{minted}[
|
||||||
@@ -1097,5 +1100,29 @@
|
|||||||
framesep=2mm,
|
framesep=2mm,
|
||||||
mathescape,
|
mathescape,
|
||||||
baselinestretch=1.1,
|
baselinestretch=1.1,
|
||||||
linenos]{#1}}
|
linenos
|
||||||
|
]{#1}}
|
||||||
{\end{minted}}
|
{\end{minted}}
|
||||||
|
|
||||||
|
% Args: Language, file relative to root file
|
||||||
|
\newcommand{\inputcode}[2]{
|
||||||
|
\inputminted[
|
||||||
|
autogobble,
|
||||||
|
breaklines,
|
||||||
|
breakindentnchars=2,
|
||||||
|
frame=lines,
|
||||||
|
framesep=2mm,
|
||||||
|
mathescape,
|
||||||
|
baselinestretch=1.1,
|
||||||
|
linenos
|
||||||
|
]{#1}{#2}
|
||||||
|
}
|
||||||
|
|
||||||
|
% Args: Language, Base directory (with trailing slash), file (no slash at start)
|
||||||
|
\newcommand{\inputcodewithfilename}[3]{
|
||||||
|
\begin{figure}[h!]
|
||||||
|
\texttt{File: \detokenize{#3}}
|
||||||
|
\rmvspace
|
||||||
|
\inputcode{#1}{#2#3}
|
||||||
|
\end{figure}
|
||||||
|
}
|
||||||
|
|||||||
BIN
docs/docs.pdf
BIN
docs/docs.pdf
Binary file not shown.
@@ -9,11 +9,14 @@ To add more sources, simply use bibter's built-in macro \verb|\addbibresource|\t
|
|||||||
You need to use that inside the preamble as well.
|
You need to use that inside the preamble as well.
|
||||||
|
|
||||||
|
|
||||||
|
% ────────────────────────────────────────────────────────────────────
|
||||||
\subsubsection{Glossary}
|
\subsubsection{Glossary}
|
||||||
\textit{Included in \texttt{recommended} and up}
|
\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|.
|
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}
|
\subsubsection{Minted}
|
||||||
\textit{Included in \texttt{full}}
|
\textit{Included in \texttt{full}}
|
||||||
|
|
||||||
@@ -37,6 +40,28 @@ Example (in python):
|
|||||||
print("hello world!")
|
print("hello world!")
|
||||||
\end{code}
|
\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}.
|
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
|
\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|}
|
||||||
|
|||||||
@@ -4,8 +4,11 @@
|
|||||||
\usepackage{minted}
|
\usepackage{minted}
|
||||||
\usepackage{fancyvrb}
|
\usepackage{fancyvrb}
|
||||||
|
|
||||||
|
% Args: Code.
|
||||||
|
% Alternative: Use \mint{<language>}|code|
|
||||||
\newcommand{\inlinecode}[1]{\shade{gray}{\texttt{#1}}}
|
\newcommand{\inlinecode}[1]{\shade{gray}{\texttt{#1}}}
|
||||||
|
|
||||||
|
% Args: Language, Code
|
||||||
\newenvironment{code}[1]{
|
\newenvironment{code}[1]{
|
||||||
\VerbatimEnvironment
|
\VerbatimEnvironment
|
||||||
\begin{minted}[
|
\begin{minted}[
|
||||||
@@ -16,5 +19,29 @@
|
|||||||
framesep=2mm,
|
framesep=2mm,
|
||||||
mathescape,
|
mathescape,
|
||||||
baselinestretch=1.1,
|
baselinestretch=1.1,
|
||||||
linenos]{#1}}
|
linenos
|
||||||
|
]{#1}}
|
||||||
{\end{minted}}
|
{\end{minted}}
|
||||||
|
|
||||||
|
% Args: Language, file relative to root file
|
||||||
|
\newcommand{\inputcode}[2]{
|
||||||
|
\inputminted[
|
||||||
|
autogobble,
|
||||||
|
breaklines,
|
||||||
|
breakindentnchars=2,
|
||||||
|
frame=lines,
|
||||||
|
framesep=2mm,
|
||||||
|
mathescape,
|
||||||
|
baselinestretch=1.1,
|
||||||
|
linenos
|
||||||
|
]{#1}{#2}
|
||||||
|
}
|
||||||
|
|
||||||
|
% Args: Language, Base directory (with trailing slash), file (no slash at start)
|
||||||
|
\newcommand{\inputcodewithfilename}[3]{
|
||||||
|
\begin{figure}[h!]
|
||||||
|
\texttt{File: \detokenize{#3}}
|
||||||
|
\rmvspace
|
||||||
|
\inputcode{#1}{#2#3}
|
||||||
|
\end{figure}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user