| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- % author Matus Necas, October 2026
- % original work by Jan Sumsky <jan.sumsky@gmail.com>, August 2024
- %
- % Description: Custom LaTeX macros for tables, figures with automatic fallbacks,
- % and equation-style code snippet environments using minted.
- % All configurable parameters are centralized as macros and lengths.
- \RequirePackage{caption}
- \mode<presentation>
- % ==============================================================================
- % Global Parameter Definitions
- % ==============================================================================
- % Code snippet layout & dimensions
- \newlength{\uniListingRefGap}
- \setlength{\uniListingRefGap}{0.07\textwidth}
- \newlength{\uniListingLeftMargin}
- \setlength{\uniListingLeftMargin}{1.5em}
- \newlength{\uniListingNumberSep}
- \setlength{\uniListingNumberSep}{5pt}
- \newlength{\uniListingFrameRule}
- \setlength{\uniListingFrameRule}{0.4pt}
- \newcommand{\uniListingFontSize}{\normalsize}
- \newcommand{\uniListingFrame}{leftline}
- % Figure placeholder dimensions
- \newlength{\uniFigPlaceholderHeight}
- \setlength{\uniFigPlaceholderHeight}{0.2\textheight}
- \newlength{\uniFigPlaceholderRule}
- \setlength{\uniFigPlaceholderRule}{0pt}
- % ==============================================================================
- % Custom Macros
- % ==============================================================================
- % Custom macro for tables
- % #1: Column specifiers (e.g., c c c or |l|r|)
- % #2: Reference label (e.g., tab:results)
- % #3: Table caption text
- % #4: Table content (rows and columns)
- \newcommand{\tab}[4]
- {%
- \begin{table}%
- \centering%
- \begin{tabular}{#1}%
- #4%
- \end{tabular}%
- \caption{#3}%
- \label{#2}%
- \end{table}%
- }
- % Custom macro for figures
- % #1: Width factor relative to line width (e.g., 0.95 for 95% \linewidth)
- % #2: Reference label (e.g., fig:overview)
- % #3: Figure caption text
- % #4: Path to the image file
- \NewDocumentCommand{\fig}{m m m m}{%
- \begin{figure}%
- \centering%
- \IfFileExists{#4}{%
- \includegraphics[width=#1\linewidth, keepaspectratio]{#4}%
- }{%
- \setlength{\fboxsep}{\uniFigPlaceholderRule}%
- \fbox{%
- \parbox[c][\uniFigPlaceholderHeight][c]{#1\linewidth}{%
- \centering
- \small Placeholder%
- }%
- }%
- }%
- \caption{#3}%
- \label{#2}%
- \end{figure}%
- }
- % Custom macro for code snippets (equation-style layout)
- % #1: Star (*) boolean flag (if present, renders code without equation counter/number)
- % #2: Programming language (e.g., python)
- % #3: Reference label (e.g., [lst:my_code])
- % #4: Path to the source code file
- \NewDocumentCommand{\code}{s m m m}{%
- \par\addvspace{\abovedisplayskip}% Vertical spacing above matching standard equations
- \noindent
- \IfBooleanTF{#1}{%
- % Starred version (\code*): Full width, no counter
- \begin{minipage}[c]{\textwidth}%
- \inputminted[
- fontsize=\uniListingFontSize,
- linenos,
- breaklines,
- autogobble,
- numbersep=\uniListingNumberSep,
- xleftmargin=\uniListingLeftMargin,
- frame=\uniListingFrame,
- framerule=\uniListingFrameRule
- ]{#2}{#4}%
- \end{minipage}%
- }{%
- % Unstarred version (\code): Code block with equation counter on the right
- \begin{minipage}[c]{\textwidth - \uniListingRefGap}%
- \inputminted[
- fontsize=\uniListingFontSize,
- linenos,
- breaklines,
- autogobble,
- numbersep=\uniListingNumberSep,
- xleftmargin=\uniListingLeftMargin,
- frame=\uniListingFrame,
- framerule=\uniListingFrameRule
- ]{#2}{#4}%
- \end{minipage}%
- \hfill
- \begin{minipage}[c]{\uniListingRefGap}%
- \centering
- \refstepcounter{codeeq}% Increment the custom code counter
- (\thecodeeq)% Display the formatted counter (e.g., (L1))
- \IfNoValueF{#3}{\label{#3}}% Apply label only if provided
- \end{minipage}%
- }%
- \par\addvspace{\belowdisplayskip}% Vertical spacing below matching standard equations
- }
- \mode <all>
|