103 lines
3.6 KiB
Markdown
103 lines
3.6 KiB
Markdown
<div class="layout-content-only">
|
|
<div class="layout-content">
|
|
<h1><span class="emoji">🖥️</span><br/>Quelltext-Listings</h1>
|
|
</div>
|
|
</div>
|
|
|
|
---
|
|
|
|
<div class="layout-content-and-preview">
|
|
<div class="layout-content">
|
|
<h2>Installation</h2>
|
|
<p>
|
|
Mit dem Paket <code>minted</code> lässt sich Quelltext gut darstellen. Dafür wird die Programmiersprache Python benötigt.
|
|
</p>
|
|
<p>
|
|
Nach der <a href="https://www.python.org/">Installation von Python</a> kann das zugehörige Paket <a href="http://pygments.org/"><code>Pygments</code></a> in der Eingabeaufforderung installiert werden durch:
|
|
</p>
|
|
<pre class="lang-bash hljs"><code>pip install Pygments</code></pre>
|
|
<p>Anschließend muss das LaTeX-Paket nur noch eingebunden werden:</p>
|
|
<pre class="lang-tex hljs"><code>\usepackage{minted}</code></pre>
|
|
</div>
|
|
<div class="layout-preview">
|
|
<img src="sections/german/10/minted-overview-crop.svg" style="padding: 2rem;">
|
|
</div>
|
|
</div>
|
|
|
|
---
|
|
|
|
<div class="layout-content-only">
|
|
<div class="layout-content">
|
|
<h2>Anpassungen beim Kompilieren</h2>
|
|
<div class="box warning">
|
|
<p>
|
|
Um Dokumente mit Quelltext-Listings kompilieren zu können, muss die Flag <code>--shell-escape</code> an den Compiler übergeben werden.
|
|
</p>
|
|
</div>
|
|
<p>
|
|
In TeXstudio muss diese unter <b><code>Optionen > TeXstudio konfigurieren > Befehle</code></b>
|
|
bei <code>PdfLaTeX</code> vor <code>%.tex</code> ergänzt werden:
|
|
</p>
|
|
<p>
|
|
<code style="hyphens: auto; font-size:85%;">pdflatex -syntex=1 -interaction=nonstopmode <b>--shell-escape</b> %.tex</code></pre>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
---
|
|
|
|
<div class="layout-content-and-preview">
|
|
<div class="layout-content">
|
|
<h2>Code im LaTeX-Quelltext</h2>
|
|
<p class="fragment">In einer eigenen Umgebung:</p>
|
|
<pre class="lang-tex hljs fragment"><code>\section{Haskell}
|
|
Quadrate aller geraden Zahlen zwischen 1 und 200:
|
|
\begin{minted}{haskell}
|
|
[x^2 | x <- [1..200], even x]
|
|
\end{minted}</code></pre>
|
|
<p class="fragment">Inline im Quelltext:</p>
|
|
<pre class="lang-tex hljs fragment"><code>\section{HTML}
|
|
Eine Überschrift wird so ausgezeichnet:
|
|
\mint{html}|<h2>LaTeX im Studium</h2>|.</code></pre>
|
|
</div>
|
|
<div class="layout-preview">
|
|
<img src="sections/german/10/minted-haskell-crop.svg">
|
|
</div>
|
|
</div>
|
|
|
|
---
|
|
|
|
<div class="layout-content-and-preview">
|
|
<div class="layout-content">
|
|
<h2>Code aus externen Dateien</h2>
|
|
<pre class="lang-tex hljs"><code>\section{Java}
|
|
\inputminted{java}{HelloWorld.java}</code></pre>
|
|
<pre class="lang-java hljs" data-sourcefile="Test.java"><code>public class HelloWorld {
|
|
public static void main(String[] args) {
|
|
System.out.println("Hello, World!");
|
|
}
|
|
}</code></pre>
|
|
</div>
|
|
<div class="layout-preview">
|
|
<img class="thin-padding" src="sections/german/10/minted-java-crop.svg">
|
|
</div>
|
|
</div>
|
|
|
|
---
|
|
|
|
<div class="layout-content-only">
|
|
<div class="layout-content">
|
|
<h2><code>Minted</code> konfigurieren</h2>
|
|
<p>
|
|
Durch optionale Parameter können Zeilennummerierung, Umbrüche, Farben und Themes für das Syntax Highlighting ausgewählt werden:
|
|
</p>
|
|
<pre class="hljs lang-tex"><code>\begin{minted}[
|
|
linenos=true,
|
|
tabsize=4,
|
|
breaklines=true,
|
|
]{javascript}
|
|
% ...
|
|
\end{minted}</code></pre>
|
|
<p><span class="emoji">🔗</span> <a href="https://www.overleaf.com/learn/latex/Code_Highlighting_with_minted">Einführung</a> und <a href="https://ctan.kako-dev.de/macros/latex/contrib/minted/minted.pdf">offizielle Dokumentation</a></p>
|
|
</div>
|
|
</div> |