Compare commits

...

6 Commits

17 changed files with 106 additions and 34 deletions

View File

@ -34,18 +34,6 @@
\rule{\widefigurewidth}{0.4pt}
}
% Listings mode
% =============
% The listings mode can be chosen by writing one of the following to the listings-mode.tex file before compilation:
% \newcommand\listingsmode{default} % to use lstlistings
% \newcommand\listingsmode{minted} % for a script with exercises only
% The following lines include that file or make \listingsmode default to 'default' so that any derivatives of this project will work even without the file.
%\IfFileExists{listings-mode.tex}{
% \input{listings-mode.tex}
%}{
% \newcommand\listingsmode{default}
%}
% Shell command
% ==============
% Mono-spaced text without syntax highlighting.

View File

@ -2,22 +2,30 @@
for D in listings/*; do
if [ -d "${D}" ]; then
# Compile without cropping.
# References to other files are interpreted relative to the
# root directory.
for F in ${D}/*_page.tex; do
if [ -f "${F}" ]; then
echo "###### Compiling ${F} ######"
pdflatex --output-directory "${D}" "${F}"
pdflatex --shell-escape --output-directory "${D}" "${F}"
fi
done
# 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
if [ -f "${F}" ]; then
echo "###### Compiling and cropping ${F} ######"
pdflatex --output-directory "${D}" "${F}"
pdfcrop "${D}/$(basename -s .tex ${F}).pdf" \
"${D}/$(basename -s .tex ${F}).pdf"
pushd "${D}"
pdflatex --shell-escape "$(basename $F)"
pdfcrop "$(basename -s .tex ${F}).pdf" \
"$(basename -s .tex ${F}).pdf"
popd
fi
done
# Compile with BibTeX and cropping.
# References to other files are interpreted relative to the
# root directory.
for F in ${D}/*_bib.tex; do
if [ -f "${F}" ]; then
echo "###### Compiling and cropping ${F} ######"

View File

@ -6,10 +6,9 @@ On some operating systems, Python comes pre-installed, in which case entering th
If Python is yet to be installed, then you can find the installation files on the project website\footnote{Available at \url{https://www.python.org/downloads/}.}.
There are extensive articles that cover all relevant steps to install Python on
Windows,\footnote{Jason Fitzpatrick, How to Install Python on Windows. How-To
Geek. July 11, 2017. Available at
\url{https://www.howtogeek.com/197947/how-to-install-python-on-windows/}.
Windows users will have to adjust the system path. Forgetting this step has
Windows,\footnote{Pawandeep, How to install Python in Windows?. Tutorialspoint. March 10, 2021. Available at
\url{https://www.tutorialspoint.com/how-to-install-python-in-windows}.
Windows users will have to adjust the system path during the installation process. Forgetting this step has
been the number one installation problem in past workshops.}
Linux,\footnote{\url{https://docs.python-guide.org/starting/install3/linux/}}
or macOS.\footnote{\url{https://docs.python-guide.org/starting/install3/osx/}}
@ -54,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.
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}).
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}).
\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}
Optional parameters allow us to add line numbers, line breaks, and colors.
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.
\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}
}

View File

@ -13,5 +13,3 @@ There are very helpful resources\footnote{If you would like to specify your own
\input{./content/source-code-listings-minted}
\input{./content/source-code-listings-listings}
\todo{Are the files minted.done.tex and listings.done.tex available in the solution-free zip? They should not.}

View File

@ -30,4 +30,8 @@ If you have questions, consult the \pkg{minted} or \pkg{listings} package docume
\end{enumerate}
\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{}
}{}

View 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}

View 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}

View File

@ -1,3 +1 @@
\inputminted{java}
{listings/source-code-listings/Test.java}
\inputminted{java}{listings/source-code-listings/Test.java}

Binary file not shown.

View 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}

Binary file not shown.

View 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}

View File

@ -1,6 +1,7 @@
\input{setup.tex} % Setup
\input{praeamble.tex} % Preamble
\input{commands.tex} % Custom commands
\title{Script for the Fachschaft \acro{WIAI} \LaTeX{} Workshop}
\author{Evelyn Fradtschuk \and Florian Knoch \and Christian Kremitzl \and Bernhard Luedtke}

View File

@ -36,7 +36,7 @@
\usepackage{todonotes}
\usepackage{changes}
% Sourcecode listings
% Source code listings
\usepackage{listings}
\ifthenelse{\equal{\listingsmode}{minted}}{\usepackage{minted}}{}

View File

@ -3,10 +3,10 @@
% The listings mode can be chosen by writing one of the following to the
%listings-mode.tex file before compilation:
% \newcommand\listingsmode{default} % to use lstlistings
% \newcommand\listingsmode{minted} % for a script with exercises only
% \newcommand\listingsmode{minted} % to use minted
% The following lines include that file or make \listingsmode default to
%'default' so that any derivatives of this project will work even without the
%file.
% 'default' so that any derivatives of this project will work even without the
% file.
\IfFileExists{listings-mode.tex}{
\input{listings-mode.tex}
}{