Skip to content

Commit

Permalink
highlight label when rule/section is highlighted
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenpieters committed Aug 5, 2023
1 parent e9dffb2 commit 7c077dd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
9 changes: 7 additions & 2 deletions data/templates/latex/template.tex
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
% Game term.
\newcommand*{\gameterm}{\small\upshape\uppercase}

\newcommand{\colorlabel}{%
\ifcolorlabel\bfseries\color{orange}\global\colorlabelfalse\fi
}
\newif\ifcolorlabel

\begin{document}

% Prelude
Expand Down Expand Up @@ -87,8 +92,8 @@ \section*{}
\newpage

% Change style for enumerate sections.
\setlist[enumerate,1]{label=\arabic{section}.\arabic{subsection}.\arabic*.,leftmargin=*,labelindent=15pt}
\setlist[enumerate,2]{label=\alph*.}
\setlist[enumerate,1]{label=\protect\colorlabel\arabic{section}.\arabic{subsection}.\arabic*.,leftmargin=50pt,labelindent=15pt}
\setlist[enumerate,2]{label=\protect\colorlabel\alph*.}

%__DOCUMENT_PLACEHOLDER__%

Expand Down
36 changes: 21 additions & 15 deletions rules_doc_generator/model/section.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,15 @@ def to_html(self, config: Config, id_map: RefDict) -> str:

def to_latex(self, config: Config, id_map: RefDict) -> str:
result = f'% SubRule {self.id}\n'
result += f' \\2 \\refstepcounter{{manual_refs}}\label{{{self.id}}} '
result += f'\\refstepcounter{{manual_refs}} \label{{{self.id}}} '
if self.new and config.annotated:
result += '\\global \\colorlabeltrue '
result += '\\2 '
if self.new and config.annotated:
result += '\\textbf{\\color{orange}'
result += '\\color{orange} \\bfseries '
result += self.format_text.to_latex(config, id_map)
if self.new and config.annotated:
result += '}'
result += '\\color{black} \\normalfont'
result += '\n'
for i, example in enumerate(self.examples):
result += f'% Example {i}\n'
Expand All @@ -111,13 +114,15 @@ def to_html(self, config: Config, id_map: RefDict) -> str:

def to_latex(self, config: Config, id_map: RefDict) -> str:
result = f'% Rule {self.id}\n'
result += '\\1 '
result += f'\\refstepcounter{{manual_refs}} \label{{{self.id}}} '
if self.new and config.annotated:
result += '\\textbf{\\color{orange}'
result += '\\global \\colorlabeltrue '
result += '\\1 '
if self.new and config.annotated:
result += '\\color{orange} \\bfseries '
result += self.format_text.to_latex(config, id_map)
if self.new and config.annotated:
result += '}'
result += '\\color{black} \\normalfont'
result += '\n'
for i, example in enumerate(self.examples):
result += f'% Example {i}\n'
Expand Down Expand Up @@ -150,22 +155,23 @@ def to_html(self, config: Config, id_map: RefDict) -> str:

def to_latex(self, config: Config, id_map: RefDict) -> str:
result = f'% SubSection {self.id}\n'
result += '\\1 '
if self.toc:
result += '\\phantomsection '
result += '\\addtocounter{subsubsection}{1} '
result += '\\addcontentsline{toc}{subsubsection}{\\arabic{section}.\\arabic{subsection}.\\arabic{subsubsection}~~ ' + self.format_text.to_latex(config, id_map) + '} '
result += f'\\refstepcounter{{manual_refs}} \label{{{self.id}}} '
if self.new and config.annotated:
result += r'\textbf{'
if self.toc:
result += r'\large '
result += r'\color{orange}'
elif self.toc:
result += '{\\large \\color{darkgray}'
result += '\\global \\colorlabeltrue '
result += '\\1 '
if self.new and config.annotated:
result += '\\color{orange} \\bfseries '
if self.toc:
result += '\\large '
if self.toc and not (self.new and config.annotated):
result += '\\bfseries \\color{darkgray}'
result += self.format_text.to_latex(config, id_map)
if self.toc or (self.new and config.annotated):
result += '}'
result += '\\color{black} \\normalfont'
result += '\n'
if self.snippet:
snippet_lines = self.snippet.to_latex(config, id_map).split('\n')
Expand Down Expand Up @@ -211,7 +217,7 @@ def to_latex(self, config: Config, id_map: RefDict) -> str:
if self.toc_entry:
result += f'\subsection[{self.toc_entry}]{{{self.text.to_latex(config, id_map)}}}\n'
elif self.new and config.annotated:
result += f'\subsection[{self.text.to_latex(config, id_map)}]{{\color{{orange}}{self.text.to_latex(config, id_map)}}}\n'
result += f'{{\color{{orange}}\subsection{{{self.text.to_latex(config, id_map)}}}}}\n'
else:
result += f'\subsection{{{self.text.to_latex(config, id_map)}}}\n'
result += f'\label{{{self.id}}}\n'
Expand Down

0 comments on commit 7c077dd

Please sign in to comment.