The LaTeX Typesetting System
LaTeX is the industry standard typesetting system that is widely used for technical and scientific document generation. It allows for precise control over document formatting and is particularly well-suited for documents that include complex mathematical equations, figures, and references. Below is an example of a simple LaTeX document that demonstrates some of its capabilities. You can copy and paste this code into a .tex file and compile it using a LaTeX editor like TeXShop on macOS or TeXworks on Windows to see how it looks.
% Place your main.c and main.cpp files in the same folder as your .tex file.
\documentclass{article}
\usepackage{minted} % For pro-level syntax coloring
\usepackage[utf8]{inputenc}
\usepackage{xcolor}
\usepackage{listings}
\usepackage{courier}
% --- Custom "Modern" Theme ---
\definecolor{mKeyword}{RGB}{0,0,255}
\definecolor{mComment}{RGB}{0,128,0}
\definecolor{mString}{RGB}{163,21,21}
\definecolor{mBackground}{RGB}{252,252,252}
\definecolor{mNumber}{RGB}{128,128,128}
\lstdefinestyle{CFileStyle}{
backgroundcolor=\color{mBackground},
commentstyle=\color{mComment},
keywordstyle=\color{mKeyword}\bfseries,
numberstyle=\tiny\color{mNumber},
stringstyle=\color{mString},
basicstyle=\ttfamily\small,
breaklines=true,
numbers=left,
numbersep=8pt,
showstringspaces=false,
tabsize=4,
language=C,
frame=single,
rulecolor=\color{black!10},
inputencoding=utf8
}
% You MUST define the style referenced in your command
\lstdefinestyle{CppFileStyle}{
backgroundcolor=\color{mBackground},
commentstyle=\color{mComment},
keywordstyle=\color{mKeyword}\bfseries,
numberstyle=\tiny\color{mNumber},
stringstyle=\color{mString},
basicstyle=\ttfamily\small,
breaklines=true,
numbers=left,
numbersep=8pt,
showstringspaces=false,
tabsize=4,
language=C++,
frame=single,
rulecolor=\color{black!20},
inputencoding=utf8
}
\begin{document}
\section*{Final Project: Source Code}
% Use this command to pull in your whole file:
% Replace 'main.c' with your actual filename
\lstinputlisting[style=CFileStyle]{./main.c}
\lstinputlisting[style=CppFileStyle]{./main.cpp}
\begin{minted}{csound}
<CsoundSynthesizer>
<CsOptions>
-odac % Outputs to digital-to-analog coverter (DAC)
-o -A oscillator1.aif % Generates/outputs a file called oscillator1.aif from this .csd file
</CsOptions>
<CsInstruments>
sr = 48000
kr = 4800
ksmps = 10
nchnls = 2
instr 1
aSigL, aSigR oscili 0.5, 440
outs aSigL, aSigR
endin
<CsInstruments>
<CsScore>
f 1 0 4096 10 1
f 1 0 4096 10 1 .5 .333 .25 .2 .166 .142 .125 .111 .1 .09 .083 .076 .071 .066 .062
f 3 0 4097 20 2 1
f 4 0 0 1 "CoinMachine.aif" 0 4 0
;P1 P2 P3
;INSTRUMENT # START-TIME DURATION
i 1 0 2
<CsScore>
<CsoundSynthesizer>
\end{minted}
\end{document}
If you copy and paste the above .tex file and name it something like CandCppSyntaxColoring.tex you can generate a .pdf with it with the following command line:
pdflatex -shell-escape CandCppSyntaxColoring.tex
(the -shell-escape flag... You have to brew install pipx
and pipx install Pygments to get the pro-leve alternative to the listings
package: The Minted Package
If you want "pro-level" highlighting without manually listing every opcode, use the minted package.
It uses the Python-based Pygments library, which has built-in support for Csound.
Pros: Better accuracy and automatic opcode recognition.
This command will generate a file titled CandCppSyntaxColoring.pdf that you can open and look
at the results with the C and C++ syntax coloring. It also generates a .log and .aux file but
all you need to know about them is that you need them in your current working directory to
keep the LaTeX compiler working and happy.