nimdoc.cls 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. \ProvidesClass{nimdoc}[2022/04/17, 2018/01/01 LaTeX2e nonstandard class]
  2. \LoadClass[a4paper,11pt]{article}
  3. \usepackage[a4paper,xetex,left=3cm,right=3cm,top=1.5cm,bottom=2cm]{geometry}
  4. % for 2-sided printing with larger inner "binding" margin
  5. %\usepackage[a4paper,xetex,twoside,left=4cm,right=2cm,top=1.5cm,bottom=2cm]{geometry}
  6. % for e-readers with 1.77:1 aspect ratio (e.g. 1920x1080)
  7. %\usepackage[xetex,paperheight=27.6cm,paperwidth=15.5cm,left=3mm,right=3mm,top=3mm,bottom=3mm]{geometry}
  8. % for e-readers with 1.45:1 aspect ratio (e.g. 1200x825)
  9. %\usepackage[xetex,paperheight=22.5cm,paperwidth=15.5cm,left=3mm,right=3mm,top=3mm,bottom=3mm]{geometry}
  10. % for e-readers with 1.33:1 aspect ratio (e.g. 1872x1404)
  11. %\usepackage[xetex,paperheight=20.7cm,paperwidth=15.5cm,left=3mm,right=3mm,top=3mm,bottom=3mm]{geometry}
  12. \usepackage{fontspec}
  13. % logic to select default font with some fall-back fonts.
  14. \IfFontExistsTF{Times New Roman}{%
  15. \setmainfont{Times New Roman} % the default font
  16. \typeout{========================================= nim: using Times New Roman}
  17. }{
  18. \IfFontExistsTF{FreeSerif}{%
  19. \setmainfont{FreeSerif} % fallback #1 - official GNU font, resembles Times
  20. \typeout{========================================= nim: using FreeSerif}
  21. }{
  22. \IfFontExistsTF{DejaVuSerif}{%
  23. \setmainfont{DejaVuSerif} % fallback #2 - very widespread free font
  24. \typeout{========================================= nim: using DejaVuSerif}
  25. }{
  26. \typeout{!!!!!!!!!!!!!!!!!!! Fonts not found !!!!!!!!!!!!!!!!!!!!!!!}
  27. }
  28. }
  29. }
  30. % default monospace font for code:
  31. \usepackage{GoMono}
  32. \usepackage{relsize}
  33. % make this monospace font 2 steps smaller to hold 80-character line
  34. \newcommand{\rstverbblockfont}{\smaller[2]}
  35. \newcommand{\rstverbinlinefont}{\smaller}
  36. \usepackage{parskip} % paragraphs delimited by vertical space, no indent
  37. \usepackage{graphicx}
  38. \usepackage{makeidx}
  39. \newcommand{\nimindexterm}[2]{#2\index{#2}\label{#1}}
  40. \makeindex
  41. \usepackage{dingbat} % for \carriagereturn, etc
  42. \usepackage{fvextra} % for code blocks (works better than original fancyvrb)
  43. \fvset{
  44. breaklines,
  45. breakafter={=}:|\_\{\}[](){,}.;+-*/'",
  46. breaksymbolleft=\color{red}{\ensuremath{\hookrightarrow}},
  47. breaksymbolright=\color{red}{\small\carriagereturn}
  48. }
  49. \fvinlineset{%
  50. breaklines,
  51. breakafter={=}:|\_\{\}[](){,}.;+-*/'",
  52. % that does not work at all when we underline inline code by ulem :-(
  53. commandchars=\\\{\}
  54. }
  55. \usepackage{scrextend} % for the `addmargin` environment
  56. \usepackage[table]{xcolor}
  57. \usepackage[urlbordercolor=blue,linkbordercolor=cyan,
  58. pdfborderstyle={/S/U/W 1}]{hyperref}
  59. \usepackage{enumitem} % for option list, enumList, and rstfootnote
  60. \usepackage[most]{tcolorbox} % boxes around admonitions, code blocks, doc.item
  61. \newtcolorbox{rstadmonition}[1][]{blanker, breakable,
  62. left=3mm, right=0mm, top=1mm, bottom=1mm,
  63. before upper=\indent, parbox=false, #1}
  64. \newtcolorbox{rstquote}[1][]{blanker, breakable,
  65. left=3mm, right=3mm, top=1mm, bottom=1mm,
  66. parbox=false,
  67. borderline west={0.3em}{0pt}{lightgray},
  68. borderline north={0.05em}{0pt}{lightgray},
  69. borderline east={0.05em}{0pt}{lightgray},
  70. borderline south={0.05em}{0pt}{lightgray}}
  71. \definecolor{rstframecolor}{rgb}{0.85, 0.8, 0.6}
  72. \usepackage{booktabs}
  73. \belowrulesep=0ex
  74. \aboverulesep=0ex
  75. \renewcommand{\arraystretch}{1.1}
  76. \newtcolorbox{rstprebox}[1][]{blanker, breakable,
  77. left=3mm, right=3mm, top=1mm, bottom=1mm,
  78. borderline ={0.1em}{0pt}{rstframecolor},
  79. before upper=\indent, parbox=false, #1}
  80. \newenvironment{rstpre}{%
  81. \VerbatimEnvironment\begingroup\begin{rstprebox}%
  82. \begin{Verbatim}[fontsize=\rstverbblockfont , commandchars=\\\{\}]}%
  83. {\end{Verbatim}\end{rstprebox}\endgroup}
  84. \newtcolorbox{rstdocitembox}[1][]{blanker, breakable,
  85. left=3mm, right=3mm, top=1mm, bottom=1mm,
  86. borderline ={1pt}{0pt}{cyan},
  87. before upper=\indent, parbox=false, #1}
  88. % Inline code formatting: grey underline,
  89. % use \Verb from fvextras e.g. to display -- correctly as double -
  90. \usepackage[normalem]{ulem}
  91. \newcommand\rstuline{\bgroup\markoverwith{\textcolor{rstframecolor}{\rule[-0.8ex]{2pt}{1.0pt}}}\ULon}
  92. \newcommand{\rstcode}[1]{%
  93. {\rstverbinlinefont\Verb{\rstuline{#1}}}%
  94. }
  95. \newcommand{\rstcodeitem}[1]{\Verb{#1}}
  96. \newenvironment{rstdocitem}{%
  97. \VerbatimEnvironment\begingroup\begin{rstdocitembox}%
  98. \begin{Verbatim}[fontsize=\rstverbblockfont , commandchars=\\\{\}]}%
  99. {\end{Verbatim}\end{rstdocitembox}\endgroup}
  100. \newenvironment{rstfootnote}{\begin{description}[labelindent=1em,leftmargin=1em,labelwidth=2.6em]}{\end{description}}
  101. \ifdim\linewidth<30em
  102. \def\rstoptleftmargin{0.4\linewidth}
  103. \def\rstoptlabelwidth{0.35\linewidth}
  104. \else
  105. \def\rstoptleftmargin{12em}
  106. \def\rstoptlabelwidth{10.5em}
  107. \fi
  108. \newenvironment{rstoptlist}{%
  109. \begin{description}[font=\sffamily\bfseries,style=nextline,leftmargin=\rstoptleftmargin,labelwidth=\rstoptlabelwidth]}{\end{description}}
  110. \usepackage{multirow}
  111. \usepackage{tabulary} % tables with adjustable cell width and no overflow
  112. % make tabulary prevent overflows (https://tex.stackexchange.com/a/195088)
  113. \tymin=60pt
  114. \tymax=\maxdimen
  115. % to pack tabulary into a new environment, special syntax is needed :-(
  116. \newenvironment{rsttab}[1]{\tabulary{\linewidth}{#1}}{\endtabulary}
  117. \newcommand{\rstsub}[1]{\raisebox{-0.5ex}{\scriptsize{#1}}}
  118. \newcommand{\rstsup}[1]{\raisebox{0.5ex}{\scriptsize{#1}}}
  119. \newcommand{\rsthA}[2][]{\section[#1]{#2}}
  120. \newcommand{\rsthB}[2][]{\subsection[#1]{#2}}
  121. \newcommand{\rsthC}[2][]{\subsubsection[#1]{#2}}
  122. \newcommand{\rsthD}[2][]{\paragraph[#1]{#2}}
  123. \newcommand{\rsthE}[2][]{\paragraph[#1]{#2}}
  124. \newcommand{\rstovA}[2][]{\section*[#1]{#2}}
  125. \newcommand{\rstovB}[2][]{\subsection*[#1]{#2}}
  126. \newcommand{\rstovC}[2][]{\subsubsection*[#1]{#2}}
  127. \newcommand{\rstovD}[2][]{\paragraph*[#1]{#2}}
  128. \newcommand{\rstovE}[2][]{\paragraph*[#1]{#2}}
  129. % Syntax highlighting:
  130. \newcommand{\spanDecNumber}[1]{\textbf{\textcolor{darkgray}{#1}}}
  131. \newcommand{\spanBinNumber}[1]{\textbf{\textcolor{darkgray}{#1}}}
  132. \newcommand{\spanHexNumber}[1]{\textbf{\textcolor{darkgray}{#1}}}
  133. \newcommand{\spanOctNumber}[1]{\textbf{\textcolor{darkgray}{#1}}}
  134. \newcommand{\spanFloatNumber}[1]{\textbf{\textcolor{darkgray}{#1}}}
  135. \newcommand{\spanIdentifier}[1]{#1}
  136. \newcommand{\spanKeyword}[1]{\textbf{#1}}
  137. \newcommand{\spanStringLit}[1]{\textbf{\textcolor{darkgray}{#1}}}
  138. \newcommand{\spanLongStringLit}[1]{\textbf{\textcolor{darkgray}{#1}}}
  139. \newcommand{\spanCharLit}[1]{#1}
  140. \newcommand{\spanEscapeSequence}[1]{#1}
  141. \newcommand{\spanOperator}[1]{\textbf{#1}}
  142. \newcommand{\spanPunctuation}[1]{#1}
  143. \newcommand{\spanComment}[1]{\emph{#1}}
  144. \newcommand{\spanLongComment}[1]{\emph{#1}}
  145. \newcommand{\spanRegularExpression}[1]{#1}
  146. \newcommand{\spanTagStart}[1]{#1}
  147. \newcommand{\spanTagEnd}[1]{#1}
  148. \newcommand{\spanKey}[1]{#1}
  149. \newcommand{\spanValue}[1]{#1}
  150. \newcommand{\spanRawData}[1]{\textbf{\textcolor{darkgray}{#1}}}
  151. \newcommand{\spanAssembler}[1]{#1}
  152. \newcommand{\spanPreprocessor}[1]{#1}
  153. \newcommand{\spanDirective}[1]{#1}
  154. \newcommand{\spanCommand}[1]{#1}
  155. \newcommand{\spanRule}[1]{#1}
  156. \newcommand{\spanHyperlink}[1]{#1}
  157. \newcommand{\spanLabel}[1]{#1}
  158. \newcommand{\spanReference}[1]{#1}
  159. \newcommand{\spanOther}[1]{#1}
  160. \newcommand{\spantok}[1]{\fbox{#1}}
  161. \newcommand{\spanPrompt}[1]{\textcolor{red}{\textbf{#1}}}
  162. \newcommand{\spanProgramOutput}[1]{\textcolor{darkgray}{\textbf{#1}}}
  163. \newcommand{\spanprogram}[1]{\textbf{\underline{#1}}}
  164. \newcommand{\spanoption}[1]{\textbf{\textcolor{darkgray}{#1}}}
  165. % Never allow text overflow to margin:
  166. \setlength\emergencystretch{\hsize}\hbadness=10000