Create minted-free alternative to the minted chapter
This commit is contained in:
parent
b9d6c531a9
commit
9df4071888
@ -2,22 +2,30 @@
|
|||||||
for D in listings/*; do
|
for D in listings/*; do
|
||||||
if [ -d "${D}" ]; then
|
if [ -d "${D}" ]; then
|
||||||
# Compile without cropping.
|
# Compile without cropping.
|
||||||
|
# References to other files are interpreted relative to the
|
||||||
|
# root directory.
|
||||||
for F in ${D}/*_page.tex; do
|
for F in ${D}/*_page.tex; do
|
||||||
if [ -f "${F}" ]; then
|
if [ -f "${F}" ]; then
|
||||||
echo "###### Compiling ${F} ######"
|
echo "###### Compiling ${F} ######"
|
||||||
pdflatex --output-directory "${D}" "${F}"
|
pdflatex --shell-escape --output-directory "${D}" "${F}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
# Compile with cropping.
|
# Compile with cropping.
|
||||||
|
# Careful: References to other files are interpreted relative
|
||||||
|
# to the file, not to the root directory.
|
||||||
for F in ${D}/*_crop.tex; do
|
for F in ${D}/*_crop.tex; do
|
||||||
if [ -f "${F}" ]; then
|
if [ -f "${F}" ]; then
|
||||||
echo "###### Compiling and cropping ${F} ######"
|
echo "###### Compiling and cropping ${F} ######"
|
||||||
pdflatex --output-directory "${D}" "${F}"
|
pushd "${D}"
|
||||||
pdfcrop "${D}/$(basename -s .tex ${F}).pdf" \
|
pdflatex --shell-escape "$(basename $F)"
|
||||||
"${D}/$(basename -s .tex ${F}).pdf"
|
pdfcrop "$(basename -s .tex ${F}).pdf" \
|
||||||
|
"$(basename -s .tex ${F}).pdf"
|
||||||
|
popd
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
# Compile with BibTeX and cropping.
|
# Compile with BibTeX and cropping.
|
||||||
|
# References to other files are interpreted relative to the
|
||||||
|
# root directory.
|
||||||
for F in ${D}/*_bib.tex; do
|
for F in ${D}/*_bib.tex; do
|
||||||
if [ -f "${F}" ]; then
|
if [ -f "${F}" ]; then
|
||||||
echo "###### Compiling and cropping ${F} ######"
|
echo "###### Compiling and cropping ${F} ######"
|
||||||
|
|||||||
@ -15,10 +15,7 @@ or macOS.\footnote{\url{https://docs.python-guide.org/starting/install3/osx/}}
|
|||||||
|
|
||||||
After a successful installation, you should be able to execute the aforementioned command in a terminal, confirm by pressing Enter, and see approximately the following result:
|
After a successful installation, you should be able to execute the aforementioned command in a terminal, confirm by pressing Enter, and see approximately the following result:
|
||||||
|
|
||||||
\begin{minted}[]{bash}
|
\codeblock{bash}{listings/source-code-listings/python-version.txt}
|
||||||
$ python --version
|
|
||||||
Python 3.8.5
|
|
||||||
\end{minted}
|
|
||||||
|
|
||||||
\noindent If the version number is equal to the one stated here, or higher, then everything should be set up correctly.
|
\noindent If the version number is equal to the one stated here, or higher, then everything should be set up correctly.
|
||||||
Next, enter the command \sh{pip install Pygments}\footnote{On some operating systems, you might have to use the command \sh{pip3 install Pygments}} in the same terminal window to install the Pygments package for Python.
|
Next, enter the command \sh{pip install Pygments}\footnote{On some operating systems, you might have to use the command \sh{pip3 install Pygments}} in the same terminal window to install the Pygments package for Python.
|
||||||
@ -56,19 +53,43 @@ Therefore, do not compile downloaded documents with the shell-escape flag if you
|
|||||||
We are finally ready to marvel at the aesthetic quality of the listings \pkg{minted} produces.
|
We are finally ready to marvel at the aesthetic quality of the listings \pkg{minted} produces.
|
||||||
You can define listings using a dedicated environment:
|
You can define listings using a dedicated environment:
|
||||||
|
|
||||||
\example{lst:minted-environment}{source-code-listings/minted-environment}{Exemplary source code listing}
|
% Render listing directly, if minted is available.
|
||||||
|
% Otherwise, include pre-rendered images.
|
||||||
|
\ifthenelse{\equal{\listingsmode}{minted}}{%
|
||||||
|
\example{lst:minted-environment}{source-code-listings/minted-environment}{Exemplary source code listing}
|
||||||
|
}{%
|
||||||
|
\Example{lst:minted-environment}{source-code-listings/minted-environment}{source-code-listings/minted-environment_crop}{Exemplary source code listing}
|
||||||
|
}
|
||||||
|
|
||||||
\example{lst:minted-variants}{source-code-listings/minted-variants}{Shorthand and inline listing}
|
% Render listing directly, if minted is available.
|
||||||
|
% Otherwise, include pre-rendered images.
|
||||||
|
\ifthenelse{\equal{\listingsmode}{minted}}{%
|
||||||
|
\example{lst:minted-variants}{source-code-listings/minted-variants}{Shorthand and inline listing}
|
||||||
|
}{%
|
||||||
|
\Example{lst:minted-variants}{source-code-listings/minted-variants}{source-code-listings/minted-variants_crop}{Shorthand and inline listing}
|
||||||
|
}
|
||||||
|
|
||||||
\noindent There is also a shorthand and an inline variant of the command (cf.\ \cref{lst:minted-variants}).
|
\noindent There is also a shorthand and an inline variant of the command (cf.\ \cref{lst:minted-variants}).
|
||||||
To avoid redundancy, it may be practical to import source code directly from the source file.
|
To avoid redundancy, it may be practical to import source code directly from the source file.
|
||||||
To accomplish this, we only have to pass the programming language and the file path to the \code{latex}{\textbackslash inputminted} command (cf.\ \cref{lst:minted-external}).
|
To accomplish this, we only have to pass the programming language and the file path to the \code{latex}{\textbackslash inputminted} command (cf.\ \cref{lst:minted-external}).
|
||||||
|
|
||||||
\example{lst:minted-external}{source-code-listings/minted-import}{Including from a separate file}
|
% Render listing directly, if minted is available.
|
||||||
|
% Otherwise, include pre-rendered images.
|
||||||
|
\ifthenelse{\equal{\listingsmode}{minted}}{%
|
||||||
|
\example{lst:minted-external}{source-code-listings/minted-import}{Including from a separate file}
|
||||||
|
}{%
|
||||||
|
\Example{lst:minted-external}{source-code-listings/minted-import}{source-code-listings/minted-import_crop}{Including from a separate file}
|
||||||
|
}
|
||||||
|
|
||||||
\subsection{Configuring minted}
|
\subsection{Configuring minted}
|
||||||
Optional parameters allow us to add line numbers, line breaks, and colors.
|
Optional parameters allow us to add line numbers, line breaks, and colors.
|
||||||
Moreover, there are numerous themes available (\cref{lst:minted-external-styled}).
|
Moreover, there are numerous themes available (\cref{lst:minted-external-styled}).
|
||||||
The introduction on Overleaf and the package documentation\footnote{Available at \url{https://www.overleaf.com/learn/latex/Code_Highlighting_with_minted} and \url{https://ctan.kako-dev.de/macros/latex/contrib/minted/minted.pdf}, respectively.} give an extensive overview.
|
The introduction on Overleaf and the package documentation\footnote{Available at \url{https://www.overleaf.com/learn/latex/Code_Highlighting_with_minted} and \url{https://ctan.kako-dev.de/macros/latex/contrib/minted/minted.pdf}, respectively.} give an extensive overview.
|
||||||
|
|
||||||
\example{lst:minted-external-styled}{source-code-listings/minted-import-styled}{Themes and further options}
|
% Render listing directly, if minted is available.
|
||||||
|
% Otherwise, include pre-rendered images.
|
||||||
|
\ifthenelse{\equal{\listingsmode}{minted}}{%
|
||||||
|
\example{lst:minted-external-styled}{source-code-listings/minted-import-styled}{Themes and further options}
|
||||||
|
}{%
|
||||||
|
\Example{lst:minted-external-styled}{source-code-listings/minted-import-styled}{source-code-listings/minted-import-styled_crop}{Themes and further options}
|
||||||
|
}
|
||||||
@ -30,4 +30,8 @@ If you have questions, consult the \pkg{minted} or \pkg{listings} package docume
|
|||||||
\end{enumerate}
|
\end{enumerate}
|
||||||
|
|
||||||
\exercisematerial{exercises/source-code-listings/source-code-listings}
|
\exercisematerial{exercises/source-code-listings/source-code-listings}
|
||||||
\usemintedstyle{} % Reset experiments from exercise material
|
|
||||||
|
% Reset experiments from exercise material if minted is used
|
||||||
|
\ifthenelse{\equal{\listingsmode}{minted}}{%
|
||||||
|
\usemintedstyle{}
|
||||||
|
}{}
|
||||||
|
|||||||
BIN
listings/source-code-listings/minted-environment_crop.pdf
Normal file
BIN
listings/source-code-listings/minted-environment_crop.pdf
Normal file
Binary file not shown.
13
listings/source-code-listings/minted-environment_crop.tex
Normal file
13
listings/source-code-listings/minted-environment_crop.tex
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
\documentclass[a4paper]{article}
|
||||||
|
\usepackage[T1]{fontenc}
|
||||||
|
\usepackage[utf8]{inputenc}
|
||||||
|
\usepackage{minted}
|
||||||
|
\begin{document}
|
||||||
|
|
||||||
|
\thispagestyle{empty}
|
||||||
|
|
||||||
|
\begin{minted}{haskell}
|
||||||
|
[x^2 | x <- [1..200], even x]
|
||||||
|
\end{minted}
|
||||||
|
|
||||||
|
\end{document}
|
||||||
BIN
listings/source-code-listings/minted-import-styled_crop.pdf
Normal file
BIN
listings/source-code-listings/minted-import-styled_crop.pdf
Normal file
Binary file not shown.
15
listings/source-code-listings/minted-import-styled_crop.tex
Normal file
15
listings/source-code-listings/minted-import-styled_crop.tex
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
\documentclass[a4paper]{article}
|
||||||
|
\usepackage[T1]{fontenc}
|
||||||
|
\usepackage[utf8]{inputenc}
|
||||||
|
\usepackage{minted}
|
||||||
|
\begin{document}
|
||||||
|
\thispagestyle{empty}
|
||||||
|
|
||||||
|
\usemintedstyle{monokai}
|
||||||
|
\definecolor{bg}{rgb}{0.1,0.1,0.2}
|
||||||
|
\inputminted[
|
||||||
|
breaklines=true,
|
||||||
|
bgcolor=bg
|
||||||
|
]{java}{Test.java}
|
||||||
|
|
||||||
|
\end{document}
|
||||||
@ -1,3 +1 @@
|
|||||||
\inputminted{java}
|
\inputminted{java}{listings/source-code-listings/Test.java}
|
||||||
{listings/source-code-listings/Test.java}
|
|
||||||
|
|
||||||
|
|||||||
BIN
listings/source-code-listings/minted-import_crop.pdf
Normal file
BIN
listings/source-code-listings/minted-import_crop.pdf
Normal file
Binary file not shown.
10
listings/source-code-listings/minted-import_crop.tex
Normal file
10
listings/source-code-listings/minted-import_crop.tex
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
\documentclass[a4paper]{article}
|
||||||
|
\usepackage[T1]{fontenc}
|
||||||
|
\usepackage[utf8]{inputenc}
|
||||||
|
\usepackage{minted}
|
||||||
|
\begin{document}
|
||||||
|
\thispagestyle{empty}
|
||||||
|
|
||||||
|
\inputminted{java}{Test.java}
|
||||||
|
|
||||||
|
\end{document}
|
||||||
BIN
listings/source-code-listings/minted-variants_crop.pdf
Normal file
BIN
listings/source-code-listings/minted-variants_crop.pdf
Normal file
Binary file not shown.
14
listings/source-code-listings/minted-variants_crop.tex
Normal file
14
listings/source-code-listings/minted-variants_crop.tex
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
\documentclass[a4paper]{article}
|
||||||
|
\usepackage[T1]{fontenc}
|
||||||
|
\usepackage[utf8]{inputenc}
|
||||||
|
\usepackage{minted}
|
||||||
|
\begin{document}
|
||||||
|
\thispagestyle{empty}
|
||||||
|
|
||||||
|
% Shorthand
|
||||||
|
Despite it is a shorthand, \mint{html}|<h2>LaTeX im Studium</h2>| will be rendered on its own line.
|
||||||
|
|
||||||
|
% Inline variant
|
||||||
|
The method call \mintinline{java}{o.doSomething();} on the other hand will appear inline.
|
||||||
|
|
||||||
|
\end{document}
|
||||||
2
listings/source-code-listings/python-version.txt
Normal file
2
listings/source-code-listings/python-version.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
$ python --version
|
||||||
|
Python 3.8.5
|
||||||
Loading…
x
Reference in New Issue
Block a user