AUTh Report LaTeX/XeLaTeX class
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

649 line
18 KiB

  1. %
  2. % AUTH report class
  3. %
  4. % note: Requires compilation with XeLaTeX or LuaTeX
  5. %
  6. % author: Christos Choutouridis <cchoutou@ece.auth.gr>
  7. %
  8. \NeedsTeXFormat{LaTeX2e}
  9. \ProvidesClass{AUThReport}[2024-12-07 AUTh Report document class]
  10. % Pre-option packages
  11. \RequirePackage{iftex}
  12. \RequirePackage{xkeyval}
  13. % Options
  14. % ===============================================
  15. % Default options
  16. \newcommand{\auth@mainlanguage}{english} % Default main language
  17. \newcommand{\auth@languages}{none} % Default list of additional languages
  18. \def\auth@short{no} % Default value for the "short" option
  19. \newcommand{\none}{none} % For comparison checks
  20. % Language append tool for option process
  21. \newcommand{\authSetupLanguageOption}[1]{%
  22. \ifx\auth@languages\none
  23. \gdef\auth@languages{#1}%
  24. \else
  25. \edef\auth@languages{\auth@languages, #1}%
  26. \fi
  27. }
  28. %
  29. % Set the default language of the document which affects:
  30. % - hyphenations
  31. % - Localization (section, dates, etc...)
  32. %
  33. % Usage: mainlang=<language>
  34. % Default: english
  35. %
  36. % example: \documentclass[mainlang=greek]{AUThReport}
  37. %
  38. \DeclareOptionX{mainlang}{
  39. \def\auth@mainlanguage{#1}
  40. }
  41. \ProcessOptionsX\relax
  42. %
  43. % Add hyphenation and typesetting support for other languages
  44. % Currently supports: english, greek, german, french
  45. %
  46. % Usage: <language>
  47. %
  48. % example: \documentclass[english, greek]{AUThReport}
  49. %
  50. \DeclareOption{english}{\authSetupLanguageOption{english}}
  51. \DeclareOption{greek}{\authSetupLanguageOption{greek}}
  52. \DeclareOption{french}{\authSetupLanguageOption{french}}
  53. \DeclareOption{german}{\authSetupLanguageOption{german}}
  54. %
  55. % Requests a shorter title for the document
  56. %
  57. % Usage: short
  58. % Default: no short
  59. %
  60. % example: \documentclass[short]{AUThReport}
  61. %
  62. \DeclareOption{short}{\def\auth@short{yes}}
  63. % Pass all other options to article
  64. \DeclareOption*{%
  65. \PassOptionsToClass{\CurrentOption}{article}%
  66. }
  67. \ProcessOptions\relax
  68. \LoadClass{article}
  69. % Requirements
  70. % ===============================================
  71. % Font packages
  72. \ifPDFTeX
  73. \RequirePackage[LGR, T1]{fontenc} % ToDo: find a way to dynamicaly select encoding based on languages
  74. \RequirePackage[utf8]{inputenc}
  75. \RequirePackage{lmodern}
  76. \else
  77. \RequirePackage{fontspec}
  78. \fi
  79. % Language packages
  80. \ifPDFTeX
  81. % Postponed to Pre-Begin hook
  82. % \usepackage{babel}
  83. \else
  84. \RequirePackage{polyglossia}%
  85. \fi
  86. \RequirePackage{xargs} % Commands
  87. \RequirePackage{geometry} % Layout
  88. \RequirePackage{fancyhdr}
  89. \RequirePackage{graphicx} % Figures
  90. \RequirePackage{wrapfig}
  91. \RequirePackage{tikz}
  92. % Format packages
  93. \RequirePackage[hang, small,labelfont=bf,up,textfont=it,up]{caption} % Custom captions under/above floats in tables or figures
  94. %\RequirePackage{caption}
  95. \RequirePackage[nobottomtitles]{titlesec}
  96. \RequirePackage{titling}
  97. \RequirePackage[bottom]{footmisc} % Place footnotes always as much to the bottom as possible.
  98. \RequirePackage{hyperref} % Various
  99. \RequirePackage[ddmmyyyy]{datetime}
  100. \RequirePackage{enumitem}
  101. \RequirePackage{multicol}
  102. % Local Tools
  103. % ===============================================
  104. % Tool to check equality
  105. \newcommand{\isequal}[2]{ \pdf@strcmp{#1}{#2} }
  106. % syntactic suggar for horizaontal rule
  107. \newcommand{\Hrule}[1]{ \rule{\linewidth}{#1} }
  108. % Dispatch between the right author(s) caption text for document title
  109. \newcommand{\authAuthorTitleText}{%
  110. \ifnum \isequal{\auth@mainlanguage}{greek}=0
  111. \ifdefined \auth@coauthorName Συντάκτες\else Συντάκτης\fi
  112. \else
  113. \ifdefined \auth@coauthorName Authors\else Author\fi
  114. \fi
  115. }
  116. % Dispatch between the right instructor(s) caption text for document title
  117. \newcommand{\authInstructorTitleText}{%
  118. \ifnum \isequal{\auth@mainlanguage}{greek}=0
  119. \ifdefined \auth@coinstructorName Διδάσκοντες\else Διδάσκων\fi
  120. \else
  121. \ifdefined \auth@coinstructorName Instructors\else Instructor\fi
  122. \fi
  123. }
  124. % Handle the language command for email href for document title
  125. \newcommand{\authMailText}[1]{%
  126. \ifnum \isequal{\auth@mainlanguage}{greek}=0
  127. \href{mailto:#1}{\eng{#1}}
  128. \else
  129. \href{mailto:#1}{#1}
  130. \fi
  131. }
  132. % Language
  133. % ===============================================
  134. %
  135. % Language setup functionality to use at the end of class.
  136. %
  137. % It uses either babel to register the languages(pdflatex) or
  138. % polyglossia (already included) to setup default and other languages
  139. %
  140. \newcommand{\authSetupLanguageEnv}{%
  141. \ifPDFTeX
  142. \ifnum \isequal{\auth@languages}{none}=0
  143. \usepackage[\auth@mainlanguage]{babel}
  144. \else
  145. \usepackage[\auth@languages, main=\auth@mainlanguage]{babel}
  146. \fi
  147. \else
  148. % Set main language
  149. \setdefaultlanguage{\auth@mainlanguage}%
  150. % Set other languages
  151. \@for\auth@lang:=\auth@languages\do{%
  152. \setotherlanguage{\auth@lang}
  153. }%
  154. \fi
  155. }
  156. % Theme
  157. % ===============================================
  158. % Layout
  159. % =====================================================
  160. % Page core layout settings (include head and foot)
  161. % A4 will result to:
  162. % Top margin: 12mm
  163. % Bottom margin: 11mm
  164. % Head hight: 14mm
  165. % Foot skip: 15mm
  166. % Left margin: 15mm
  167. % Right margin: 12mm
  168. \newcommand{\authTopMargin}{10mm}
  169. \newcommand{\authBottomMargin}{10mm}
  170. \newcommand{\authHeadHeight}{10mm}
  171. \newcommand{\authFootSkip}{10mm}
  172. \newcommand{\authLeftMargin}{15mm}
  173. \newcommand{\authRightMargin}{15mm}
  174. %
  175. % Sets page layout. (include head and foot)
  176. \newcommand*{\authSetPageLayout}{%
  177. \newgeometry{%
  178. includeheadfoot,
  179. top= \authTopMargin,
  180. bottom= \authBottomMargin,
  181. headheight= \authHeadHeight,
  182. footskip= \authFootSkip,
  183. lmargin= \authLeftMargin,
  184. rmargin= \authRightMargin
  185. }
  186. }
  187. % Fonts
  188. % =====================================================
  189. %
  190. % Setup fonts (computer modern)
  191. %
  192. \newcommand{\authSetupFontEnv}{%
  193. \ifPDFTeX
  194. % PDFLaTeX fonts
  195. \else
  196. % \setmainfont{CMU-Serif-Roman}[%
  197. %% Path=~/texmf/tex/latex/local/AUThReport/cmu/,
  198. % ItalicFont = CMU-Serif-Italic,
  199. % BoldFont = CMU-Serif-Bold,
  200. % BoldItalicFont= CMU-Serif-BoldItalic
  201. % ]
  202. % \setsansfont{CMU-Sans-Medium}[%
  203. %% Path=~/texmf/tex/latex/local/AUThReport/cmu/,
  204. % ItalicFont = CMU-Sans-Oblique,
  205. % BoldFont = CMU-Sans-Bold,
  206. % BoldItalicFont= CMU-Sans-BoldOblique
  207. % ]
  208. % %\setsansfont{CMU-Concrete-Roman}[%
  209. % % Path=~/texmf/tex/latex/local/AUThReport/cmu/,
  210. % % ItalicFont = CMU-Concrete-Italic,
  211. % % BoldFont = CMU-Concrete-Bold,
  212. % % BoldItalicFont= CMU-Concrete-BoldItalic
  213. % %]
  214. % \setmonofont{CMU-Typewriter-Regular}[%
  215. %% Path=~/texmf/tex/latex/local/AUThReport/cmu/,
  216. % ItalicFont = CMU-Typewriter-Oblique,
  217. % BoldFont = CMU-Typewriter-Bold,
  218. % BoldItalicFont= CMU-Typewriter-Oblique
  219. % ]
  220. % \typeout{[DEBUG] set fonts}
  221. \setmainfont{CMU Serif}
  222. \setsansfont{CMU Sans Serif}
  223. \setmonofont{CMU Typewriter Text}
  224. % \setmonofont{Courier New}
  225. \fi
  226. }
  227. % Header and Footer
  228. % =====================================================
  229. %
  230. % Clear footer command
  231. %
  232. \newcommand*{\authSetFooterEmpty}{%
  233. % Clear styles
  234. \fancyfoot{}
  235. \renewcommand{\footrulewidth}{0pt}
  236. }
  237. %
  238. % Setup footer according to theme
  239. %
  240. \newcommand*{\authSetFooter}{%
  241. % Clear styles
  242. \fancyfoot{}
  243. \fancyfoot[C]{\thepage}
  244. \renewcommand{\footrulewidth}{0pt}
  245. \pagenumbering{arabic}
  246. }
  247. %
  248. % Clear header command
  249. %
  250. \newcommand{\authSetHeaderEmpty}{
  251. % Clear styles
  252. \fancyhead{}
  253. \renewcommand{\headrulewidth}{0pt}
  254. }
  255. %
  256. % Setup header according to theme
  257. %
  258. \newcommand{\authSetHeader}{
  259. % Clear styles
  260. \fancyhead{}
  261. \fancyhead[L]{\auth@className}
  262. \fancyhead[R]{\auth@docTitle}
  263. \renewcommand{\headrulewidth}{0.5pt}
  264. }
  265. %
  266. % Page styles
  267. %
  268. % Plain: the main style of the document (including TOC if any)
  269. \fancypagestyle{plain}{%
  270. \authSetFooter
  271. \authSetHeader
  272. }
  273. % authTitlePageStyle: The style for the title page
  274. \fancypagestyle{authTitlePageStyle}{%
  275. % Style for Title page
  276. \authSetHeaderEmpty
  277. \ifnum \isequal{\auth@short}{no}=0
  278. \authSetFooterEmpty
  279. \else
  280. \authSetFooter
  281. \fi
  282. }
  283. % Page content look and feel style
  284. \newcommand{\authPageStyle}{%
  285. \renewcommand{\bottomtitlespace}{0.12\textheight}
  286. % Change the look of the section and subsection titles
  287. \titleformat{\section}[block]{\large\scshape}{\thesection.}{1em}{}
  288. \titleformat{\subsection}[block]{\large}{\thesubsection.}{1em}{}
  289. \titleformat{\subsubsection}[block]{\normalsize}{\thesubsubsection.}{1em}{}
  290. %\setlist[itemize]{noitemsep} % Make itemize lists more compact
  291. \setlist[itemize]{topsep=2pt, partopsep=0pt, itemsep=1pt, parsep=1pt}
  292. \setlist[enumerate]{topsep=2pt, partopsep=0pt, itemsep=1pt, parsep=1pt}
  293. % Set paragraph identation and skip
  294. \setlength{\parindent}{0pt}
  295. \setlength{\parskip}{0.3em}
  296. }
  297. % Setup theme
  298. % =====================================================
  299. \AtEndOfClass{%
  300. \hypersetup{
  301. colorlinks=true,
  302. linkcolor=red, % Internal links, those generated by cross-referenced elements
  303. filecolor=blue, % Links to local files
  304. urlcolor=blue % Links to web sites
  305. }
  306. % Language and fonts
  307. \ifPDFTeX
  308. \authSetupLanguageEnv % Before fonts
  309. \authSetupFontEnv
  310. \else
  311. \authSetupFontEnv
  312. \authSetupLanguageEnv % After fonts
  313. \fi
  314. \typeout{[AUThReport] Main language: \auth@mainlanguage}
  315. \typeout{[AUThReport] Other languages: \auth@languages}
  316. \typeout{[AUThReport] Short title: \auth@short}
  317. }
  318. \AtBeginDocument{%
  319. % Page layout (check above for the geometry setup)
  320. \authSetPageLayout
  321. %hyphenation settiongs
  322. \lefthyphenmin=2 % minimum characters before
  323. \righthyphenmin=2 % minimum characters after
  324. % ToDo:
  325. % Something wrong is going on with fancy header for LaTeX
  326. % In greek (main) the text are in the wrong language configurations
  327. % Header - Footer
  328. \pagestyle{plain}
  329. \thispagestyle{authTitlePageStyle}
  330. % Page styles and formating
  331. \authPageStyle
  332. \normalsize
  333. } % End \AtBeginDocument
  334. % Public environments/commands
  335. % =====================================================
  336. % Common fields
  337. % =====================================================
  338. \newcommand*{\AuthorName}[1]{\def\auth@authorName{#1}}
  339. \newcommand*{\AuthorMail}[1]{\def\auth@authorMail{#1}}
  340. \newcommand*{\AuthorAEM}[1]{\def\auth@authorAEM{#1}}
  341. \newcommand*{\CoAuthorName}[1]{\def\auth@coauthorName{#1}}
  342. \newcommand*{\CoAuthorMail}[1]{\def\auth@coauthorMail{#1}}
  343. \newcommand*{\CoAuthorAEM}[1]{\def\auth@coauthorAEM{#1}}
  344. \newcommand*{\WorkGroup}[1]{\def\auth@workGroup{#1}}
  345. \newcommand*{\DocTitle}[1]{\def\auth@docTitle{#1}}
  346. \newcommand*{\DocSubTitle}[1]{\def\auth@docSubTitle{#1}}
  347. \newcommand*{\Department}[1]{\def\auth@department{#1}}
  348. \newcommand*{\ClassName}[1]{\def\auth@className{#1}}
  349. \newcommand*{\InstructorName}[1]{\def\auth@instructorName{#1}}
  350. \newcommand*{\InstructorMail}[1]{\def\auth@instructorMail{#1}}
  351. \newcommand*{\CoInstructorName}[1]{\def\auth@coinstructorName{#1}}
  352. \newcommand*{\CoInstructorMail}[1]{\def\auth@coinstructorMail{#1}}
  353. \newcommand*{\CurrentDate}[1]{\def\auth@date{#1}}
  354. % Language manipulation commands
  355. % =====================================================
  356. % \eng{}
  357. % syntactic suggar for english text inside greek
  358. % example \eng{A quick brown fox jumpedover the lazy dog}
  359. \newcommand{\eng}[1]{%
  360. \ifPDFTeX
  361. \foreignlanguage{english}{#1}
  362. \else
  363. #1
  364. \fi
  365. }
  366. % \gr{}
  367. % syntactic suggar for greek text inside english
  368. % example \gr{Άσπρη πέτρα ξέξασπρη κι απτον ήλιο ξεξασπρότερη}
  369. \newcommand{\gr}[1]{%
  370. \ifPDFTeX
  371. \foreignlanguage{greek}{#1}
  372. \else
  373. #1
  374. \fi
  375. }
  376. % \setEnglish
  377. % Selects english for the rest of the text
  378. \newcommand{\setEnglish}{%
  379. \ifPDFTeX \selectlanguage{english} \fi
  380. }
  381. % \setGreek
  382. % Selects greek for the rest of the text
  383. \newcommand{\setGreek}{%
  384. \ifPDFTeX \selectlanguage{greek} \fi
  385. }
  386. % Content commands
  387. % =====================================================
  388. %
  389. %
  390. %
  391. \newcommand{\authInsertAuthsInstructors}{%
  392. \center
  393. \noindent
  394. % Authors
  395. \hspace*{0.05\textwidth}
  396. \begin{minipage}[t]{0.35\textwidth}
  397. \begin{flushleft}
  398. \large
  399. \ifdefined \auth@workGroup \emph{\textsc{\auth@workGroup}} \\[2ex]\fi
  400. \emph{\authAuthorTitleText:} \\
  401. \auth@authorName\hspace{1ex}[\auth@authorAEM] \\[0.35ex]
  402. \normalsize \authMailText{\auth@authorMail} \\[2ex]
  403. \large
  404. \ifdefined \auth@coauthorName
  405. \auth@coauthorName\hspace{1ex}[\auth@coauthorAEM] \\[0.35ex]
  406. \normalsize \authMailText{\auth@coauthorMail} \\[2ex]
  407. \fi
  408. \end{flushleft}
  409. \end{minipage}
  410. \hfill
  411. % Instructors
  412. \begin{minipage}[t]{0.35\textwidth}
  413. \begin{flushright}
  414. \large
  415. \emph{\authInstructorTitleText:} \\
  416. \auth@instructorName \\[0.35ex]
  417. \normalsize \authMailText{\auth@instructorMail} \\[2ex]
  418. \large
  419. \ifdefined \auth@coinstructorName
  420. \auth@coinstructorName \\[0.35ex]
  421. \normalsize \authMailText{\auth@coinstructorMail} \\[2ex]
  422. \fi
  423. \end{flushright}
  424. \end{minipage}
  425. \hspace*{0.05\textwidth}
  426. }
  427. % \FirstPage
  428. \newcommand{\authTitlePage}[3]{%
  429. \begin{titlepage}
  430. % Logo
  431. \begin{figure}
  432. \begin{flushleft}
  433. \vspace{-1cm}
  434. \includegraphics[width=5cm]{img/auth_logogr.png}
  435. \end{flushleft}
  436. \end{figure}
  437. \ifnum \isequal{#1}{none}=0 \else
  438. \begin{tikzpicture}[remember picture, overlay]
  439. \node[anchor=center, opacity=0.25] at ([yshift=#3] current page.center) {
  440. \includegraphics[width=#2]{#1}
  441. };
  442. \end{tikzpicture}
  443. \fi
  444. % Titles
  445. \center
  446. \textbf{} \\[1cm] % vertical space
  447. \textsc{\Large \auth@department} \\[0.5cm] % Department
  448. \textsc{\Large \auth@className} \\[4.0cm] % Class/Course name
  449. {\huge \bfseries \auth@docTitle} \\[0.3cm] % Document/Assignement Title
  450. \ifdefined \auth@docSubTitle
  451. {\Large \bfseries \auth@docSubTitle} \\ % Document/Assignement Sub-Title
  452. \fi
  453. %\Hrule{0.2mm} % -------
  454. \vfill
  455. % Authors-Instructors
  456. \authInsertAuthsInstructors \\
  457. \vspace{1.5cm}
  458. {\large \auth@date} \\ % date
  459. \end{titlepage}
  460. \newpage
  461. }
  462. % \TitleHeader
  463. \newcommand{\authTitleHeader}{%
  464. \begin{center} % Center everything on the page
  465. % Logo
  466. \noindent
  467. \begin{figure}
  468. \vspace{-1.5cm}
  469. \center
  470. \includegraphics[width=5cm]{img/auth_logogr.png}
  471. \end{figure}
  472. % Titles
  473. \textsc{\Large \auth@department} \\[0.4cm] % Department
  474. \textsc{\Large \auth@className} \\[0.8cm] % Class/Course name
  475. {\Large \bfseries \auth@docTitle} \\[0.2cm] % Document/Assignement Title
  476. \ifdefined \auth@docSubTitle
  477. {\large \bfseries \auth@docSubTitle} \\[0.2cm] % Document/Assignement Sub-Title
  478. \fi
  479. {\large \auth@date} \\[0.4cm] % date
  480. % Authors-Instructors
  481. \authInsertAuthsInstructors
  482. \end{center}
  483. }
  484. %
  485. % Inserts titles, author(s), instructor(s) as a first page or header
  486. %
  487. % [1]: Optional background image
  488. % [2]: Optional width of the image (if argument 1 is used)
  489. % [3]: Optional y shift for image positioning (if argument 1 is used)
  490. %
  491. % examples:
  492. % - \InsertFigure
  493. % - \InsertFigure[myBackgroung]
  494. % - \InsertFigure[myBackgroung][0.9\textwidth][2cm]
  495. %
  496. \newcommandx{\InsertTitle}[3][1=none, 2=\textwidth, 3=0mm]{%
  497. \ifnum \isequal{\auth@short}{no}=0
  498. \authTitlePage{#1}{#2}{#3}
  499. \else
  500. \authTitleHeader
  501. \fi
  502. }
  503. %
  504. % \InsertFigure{}{}{}{}{}
  505. %
  506. % [1]: Position specifier
  507. % [2]: scale
  508. % [3]: Label
  509. % [4]: Figure file
  510. % [5]: Caption text
  511. % example: \InsertFigure{!h}{0.8}{fig:lala}{lala.png}{\eng{Makes lala}}
  512. %
  513. % ToDo:
  514. % Something iswrong with InserFigures in general. In LaTeX the combination
  515. % titlepage and begin{figure} creates problems.
  516. %
  517. \newcommand{\InsertFigure}[5]{
  518. \begin{figure}[#1]
  519. \captionsetup{
  520. format=plain, % Plain format
  521. labelfont={bf,up}, % Bold and upright for label
  522. textfont={it,up}, % Italic and upright for text
  523. justification=centering,
  524. singlelinecheck=false
  525. }
  526. \centering
  527. \includegraphics[width=#2\textwidth]{#4}
  528. \caption{#5}
  529. \label{#3}
  530. \end{figure}
  531. }
  532. %
  533. % \WrapFigure{}{}{}{}
  534. %
  535. % [1]: scale
  536. % [2]: place left or right r,l,R,L
  537. % [3]: Label
  538. % [4]: Figure file
  539. % [5]: Caption text
  540. % example: \WrapFigure{0.8}{r}{fig:lala}{lala.png}{\eng{Makes lala}}
  541. \newcommand{\WrapFigure}[5]{
  542. \begin{wrapfigure}{#2}{#1\textwidth}
  543. \vspace{-20pt}
  544. \begin{center}
  545. \captionsetup{
  546. format=plain, % Plain format
  547. labelfont={bf,up}, % Bold and upright for label
  548. textfont={it,up}, % Italic and upright for text
  549. justification=centering,
  550. singlelinecheck=false
  551. }
  552. \includegraphics[width=#1\textwidth]{#4}
  553. \caption{#5}
  554. \label{#3}
  555. \end{center}
  556. \vspace{-20pt}
  557. \end{wrapfigure}
  558. }