contents.sty 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. % author Matus Necas, October 2026
  2. % original work by Jan Sumsky <jan.sumsky@gmail.com>, August 2024
  3. %
  4. % Description: Custom LaTeX macros for tables, figures with automatic fallbacks,
  5. % and equation-style code snippet environments using minted.
  6. % All configurable parameters are centralized as macros and lengths.
  7. \RequirePackage{caption}
  8. \mode<presentation>
  9. % ==============================================================================
  10. % Global Parameter Definitions
  11. % ==============================================================================
  12. % Code snippet layout & dimensions
  13. \newlength{\uniListingRefGap}
  14. \setlength{\uniListingRefGap}{0.07\textwidth}
  15. \newlength{\uniListingLeftMargin}
  16. \setlength{\uniListingLeftMargin}{1.5em}
  17. \newlength{\uniListingNumberSep}
  18. \setlength{\uniListingNumberSep}{5pt}
  19. \newlength{\uniListingFrameRule}
  20. \setlength{\uniListingFrameRule}{0.4pt}
  21. \newcommand{\uniListingFontSize}{\normalsize}
  22. \newcommand{\uniListingFrame}{leftline}
  23. % Figure placeholder dimensions
  24. \newlength{\uniFigPlaceholderHeight}
  25. \setlength{\uniFigPlaceholderHeight}{0.2\textheight}
  26. \newlength{\uniFigPlaceholderRule}
  27. \setlength{\uniFigPlaceholderRule}{0pt}
  28. % ==============================================================================
  29. % Custom Macros
  30. % ==============================================================================
  31. % Custom macro for tables
  32. % #1: Column specifiers (e.g., c c c or |l|r|)
  33. % #2: Reference label (e.g., tab:results)
  34. % #3: Table caption text
  35. % #4: Table content (rows and columns)
  36. \newcommand{\tab}[4]
  37. {%
  38. \begin{table}%
  39. \centering%
  40. \begin{tabular}{#1}%
  41. #4%
  42. \end{tabular}%
  43. \caption{#3}%
  44. \label{#2}%
  45. \end{table}%
  46. }
  47. % Custom macro for figures
  48. % #1: Width factor relative to line width (e.g., 0.95 for 95% \linewidth)
  49. % #2: Reference label (e.g., fig:overview)
  50. % #3: Figure caption text
  51. % #4: Path to the image file
  52. \NewDocumentCommand{\fig}{m m m m}{%
  53. \begin{figure}%
  54. \centering%
  55. \IfFileExists{#4}{%
  56. \includegraphics[width=#1\linewidth, keepaspectratio]{#4}%
  57. }{%
  58. \setlength{\fboxsep}{\uniFigPlaceholderRule}%
  59. \fbox{%
  60. \parbox[c][\uniFigPlaceholderHeight][c]{#1\linewidth}{%
  61. \centering
  62. \small Placeholder%
  63. }%
  64. }%
  65. }%
  66. \caption{#3}%
  67. \label{#2}%
  68. \end{figure}%
  69. }
  70. % Custom macro for code snippets (equation-style layout)
  71. % #1: Star (*) boolean flag (if present, renders code without equation counter/number)
  72. % #2: Programming language (e.g., python)
  73. % #3: Reference label (e.g., [lst:my_code])
  74. % #4: Path to the source code file
  75. \NewDocumentCommand{\code}{s m m m}{%
  76. \par\addvspace{\abovedisplayskip}% Vertical spacing above matching standard equations
  77. \noindent
  78. \IfBooleanTF{#1}{%
  79. % Starred version (\code*): Full width, no counter
  80. \begin{minipage}[c]{\textwidth}%
  81. \inputminted[
  82. fontsize=\uniListingFontSize,
  83. linenos,
  84. breaklines,
  85. autogobble,
  86. numbersep=\uniListingNumberSep,
  87. xleftmargin=\uniListingLeftMargin,
  88. frame=\uniListingFrame,
  89. framerule=\uniListingFrameRule
  90. ]{#2}{#4}%
  91. \end{minipage}%
  92. }{%
  93. % Unstarred version (\code): Code block with equation counter on the right
  94. \begin{minipage}[c]{\textwidth - \uniListingRefGap}%
  95. \inputminted[
  96. fontsize=\uniListingFontSize,
  97. linenos,
  98. breaklines,
  99. autogobble,
  100. numbersep=\uniListingNumberSep,
  101. xleftmargin=\uniListingLeftMargin,
  102. frame=\uniListingFrame,
  103. framerule=\uniListingFrameRule
  104. ]{#2}{#4}%
  105. \end{minipage}%
  106. \hfill
  107. \begin{minipage}[c]{\uniListingRefGap}%
  108. \centering
  109. \refstepcounter{codeeq}% Increment the custom code counter
  110. (\thecodeeq)% Display the formatted counter (e.g., (L1))
  111. \IfNoValueF{#3}{\label{#3}}% Apply label only if provided
  112. \end{minipage}%
  113. }%
  114. \par\addvspace{\belowdisplayskip}% Vertical spacing below matching standard equations
  115. }
  116. \mode <all>