Skip to content

Commit

Permalink
Better Náboj templates and i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
sesquideus committed Nov 12, 2024
1 parent af66423 commit 9e8ef76
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 87 deletions.
2 changes: 1 addition & 1 deletion core/i18n/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def as_dict(self):
figure='figure', figures='figures', ### must be present for validation
table='table', tables='tables',
equation='equation', equations='equations',
section='section', sections='sectionss'),
section='section', sections='sections'),
Locale('qq', 'test', 'sk-SK', ('(', ')'),
figure='obrázok', figures='obrázky',
table='tabuľka', tables='tabuľky',
Expand Down
10 changes: 8 additions & 2 deletions core/markdown-check.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def __init__(self):
self.parser.add_argument('-v', '--verbose', action='store_true')
self.parser.add_argument('-w', '--warnings', action='store_true')
self.parser.add_argument('--only', nargs='+', type=str)
self.parser.add_argument('--ignore', nargs='+', type=str)
self.parser.add_argument('--markdown', action='store_true')
self.args = self.parser.parse_args()

Expand All @@ -29,12 +30,13 @@ def __init__(self):
self.line_errors = {
'tab': check.FailIfFound(r'\t', "Tab instead of spaces"),
'cws': check.FailIfFound(r',[^\s^]', "Comma not followed by whitespace"),
'sws': check.FailIfFound(r'(?<!\\ang{;?|\\SIlist{[0-9.e;]+|\\Coord{[0-9.e;]+);[^\s]', "Semicolon not followed by whitespace"),
'sws': check.FailIfFound(r'(?<!\\ang{;?|\\qtylist{[0-9.e;]+|\\Coord{[0-9.e;]+);[^\s]', "Semicolon not followed by whitespace"),
'pas': check.ParenthesesSpace(),
'tws': check.FailIfFound(r'(?! )[ \t]$', "Trailing whitespace"),
'spb': check.FailIfFound(r'[^ ]\\\\$', "No space before ending \\\\", offset=1),
'frb': check.FailIfFound(r'\\frac[^{]', "\\frac not followed by a brace", offset=5),
'csi': check.FailIfFound(r'(?:SI\{[^},]*),', "Comma in \\SI expression", offset=0),
'csi': check.FailIfFound(r'(?:qty\{[^},]*),', "Comma in \\qty expression", offset=0),
'osi': check.FailIfFound(r'\\SI', "Use \\qty instead of SI"),
'cnu': check.FailIfFound(r'(?:\\num\{[^},]*),', "Comma in \\num expression"),
'vep': check.FailIfFound(r'\\varepsilon', "\\varepsilon is not allowed, use plain \\epsilon"),
'crc': check.FailIfFound(r'\^\{?\\circ\}?', "\\circ is not allowed, use \\ang{...} instead", offset=2),
Expand Down Expand Up @@ -125,6 +127,10 @@ def check_markdown_file(self, path):
if self.args.only is not None:
line_errors = {key: error for key, error in line_errors.items() if key in self.args.only}

if self.args.ignore is not None:
for key in self.args.ignore:
del line_errors[key]

with open(path, 'r') as file:
ok = None
for number, line in enumerate(file):
Expand Down
34 changes: 0 additions & 34 deletions modules/naboj/builder/contexts/hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,53 +79,19 @@ class ContextVenue(ContextNaboj):
'code': Regex(r'[A-Z]{5}'),
'name': And(str, len),
'language': valid_language,
'teams': [ContextNaboj.team],
'teams_grouped': [[ContextNaboj.team]],
'problems_modulo': [[ContextNaboj.problem]],
Optional('orgs'): [And(str, len)],
'evaluators': int,
'start': And(int, lambda x: 0 <= x < 1440),
})

def _add_extra_teams(self, competition, venue):
code = 0
while len(self.data['teams']) % competition.data['tearoff']['per_page'] != 0:
self.data['teams'].append({
'id': 0,
'code': f'SKBAS{999 - code}',
'contact_email': "[email protected]",
'contact_name': "Unnamed",
'contact_phone': "",
'contestants': "unknown",
'display_name': f"Extra set {999 - code}",
'in_school_symbol': None,
'language': self.data['language'],
'name': "",
'number': 0,
'school': f"Extra set {999 - code}",
'school_address': "",
'school_id': 0,
'school_name': f"Extra set {999 - code}",
'status': 'R',
'venue': self.data['id'],
'venue_code': self.data['code'],
'venue_id': 0,
#'venue_id': self.data['id'], # Currently there is a collision with venue.id from web!!! Fix later
})
code += 1

def populate(self, competition, volume, venue):
super().populate(competition)
comp = ContextCompetition(self.root, competition)
vol = ContextVolume(self.root, competition, volume)
self.load_meta(competition, volume, venue) \
.add_id(venue)
self._add_extra_teams(comp, vol)
self.add(
teams=lists.numerate(self.data.get('teams'), itertools.count(0)),
teams_grouped=lists.split_div(
lists.numerate(self.data.get('teams')), comp.data['tearoff']['per_page']
),
problems_modulo=lists.split_mod(
lists.add_numbers([x['id'] for x in vol.data['problems']], itertools.count(1)),
self.data['evaluators'], first=1,
Expand Down
3 changes: 2 additions & 1 deletion modules/naboj/builder/language.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ class BuilderNabojLanguage(BuilderNaboj):
'cover.jtt',
'instructions-online.jtt',
'online.jtt',
'evaluation.jtt',
'tearoff.jtt',
]
i18n_templates = ['intro.jtt']
i18n_templates = ['intro.jtt', 'evaluators.jtt']

def add_arguments(self):
super().add_arguments()
Expand Down
3 changes: 1 addition & 2 deletions modules/naboj/builder/venue.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ class BuilderNabojVenue(BuilderNaboj):

_root_context_class = BuildableContextVenue
templates = [
'envelopes.jtt',
'instructions.jtt',
'answers-modulo.jtt',
]
language_templates = ['instructions-inner.jtt', 'evaluators.jtt']
language_templates = ['instructions-inner.jtt']

def add_arguments(self):
super().add_arguments()
Expand Down
61 changes: 25 additions & 36 deletions modules/naboj/module.mk
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ build/naboj/%/build-venue: \

### Input files ###################################################################################

# % <competition>/<volume>/venues/<venue>
build/naboj/%/envelopes.tex: \
modules/naboj/templates/envelopes.jtt \
build/naboj/$$*/build-venue ;

# Language-specific documents: booklet, answer sheet, answer sheet for evaluators, booklet cover
# % <competition>/<volume>/languages/<language>
build/naboj/%/online.tex: \
Expand Down Expand Up @@ -112,19 +107,20 @@ build/naboj/%/constants.tex: \
# Instructions to be put on the table before the competition (content)
# % <competition>/<volume>/venues/<venue>
build/naboj/%/instructions-inner.tex: \
source/naboj/$$*/$$(subst .tex,.jtt,$$(notdir $$@)) \
build/naboj/$$*/build-language ;

build/naboj/%/evaluators.tex: \
source/naboj/$$*/$$(subst .tex,.jtt,$$(notdir $$@)) \
$$(wildcard $$(subst $(cdir),,$$(abspath source/naboj/$$*/../../languages/*/instructions-inner.md))) \
build/naboj/$$*/build-venue ;

# Instructions to be put on the table before the competition (full document)
# % <competition>/<volume>/venues/<venue>
build/naboj/%/instructions.tex: \
modules/naboj/templates/$$(notdir $$@) \
modules/naboj/templates/$$(subst .tex,.jtt,$$(notdir $$@)) \
build/naboj/$$*/build-venue ;

# % <competition>/<volume>/languages/<language>
build/naboj/%/evaluators.tex: \
source/naboj/$$*/$$(subst .tex,.jtt,$$(notdir $$@)) \
build/naboj/$$*/build-language ;

# Instructions before the online competition (content)
build/naboj/%/instructions-online-inner.tex: \
source/naboj/$$*/_extras/instructions-online-inner.md
Expand Down Expand Up @@ -200,19 +196,6 @@ build/naboj/%/answers-modulo.tex: \
modules/naboj/templates/answers-modulo.jtt \
build/naboj/$$*/build-venue ;

# Barcodes in text format
build/naboj/%/barcodes.tex: \
build/naboj/$$*/build-venue ;

# Barcodes text -> PDF, one per page
build/naboj/%/barcodes.pdf: \
build/naboj/%/barcodes.tex
@echo -e '$(c_action)Creating barcode PDF file $(c_filename)$@$(c_action):$(c_default)'
barcode -e "128" -i $< -g "120x30" -p "120x30mm" -n -o $(subst .tex,.ps,$<)
ps2pdf $(subst .tex,.ps,$<) $@.big
pdfcrop $@.big $@



### Output files ##################################################################################
### Languages ###################################
Expand Down Expand Up @@ -258,6 +241,10 @@ output/naboj/%/constants.pdf: \
source/naboj/%/i18n
$(call double_xelatex,naboj)

output/naboj/%/evaluation.pdf: \
build/naboj/%/evaluators.tex
$(call double_xelatex,naboj)

output/naboj/%/instructions-online.pdf: \
build/naboj/%/pdf-prerequisites \
build/naboj/%/instructions-online.tex \
Expand Down Expand Up @@ -299,6 +286,7 @@ output/naboj/%: \
output/naboj/%/constants.pdf \
output/naboj/%/cover-print.pdf \
output/naboj/%/booklet.pdf \
output/naboj/%/evaluation.pdf \
output/naboj/%/booklet-print.pdf ;
# output/naboj/$$*/instructions-online.pdf \
# output/naboj/$$*/online.pdf ;
Expand All @@ -313,15 +301,11 @@ output/naboj/%/languages: \
$$(foreach dir,$$(subst source/,output/,$$(wildcard source/naboj/$$*/languages/*)),$$(dir)) \
$$@/tearoffs.zip ;

# Envelope cover
output/naboj/%/envelopes.pdf: \
build/naboj/%/envelopes.tex
$(call double_xelatex,naboj)

# <competition>/<volume>/venues/<venue>
output/naboj/%/instructions.pdf: \
build/naboj/%/instructions.tex \
$$(subst source/,build/,$$(wildcard $$(subst $(cdir),,$$(abspath source/naboj/$$*/../../languages/*/instructions-inner.tex)))) \
source/naboj/%/i18n
build/naboj/$$*/build-venue
$(call double_xelatex,naboj)

# <competition>/<volume>/venues/<venue>
Expand All @@ -334,22 +318,27 @@ output/naboj/%/answers-modulo.pdf: \
$$(subst $$(cdir),,$$(abspath build/naboj/%/../../answers)) \
$$(subst $$(cdir),,$$(abspath build/naboj/%/../../pdf-prerequisites)) \
build/naboj/%/answers-modulo.tex \
build/naboj/%/evaluators.tex
build/naboj/$$*/build-venue \
build/core/i18n ;
$(call double_xelatex,naboj)



# All targets for <venue>
# <competition>/<volume>/venues/<venue>
output/naboj/%: \
output/naboj/%/booklet-print.pdf \
output/naboj/%/tearoff.pdf \
output/naboj/%/instructions.pdf \
output/naboj/%/answers-modulo.pdf \
output/naboj/%/envelopes.pdf ;
output/naboj/%/answers-modulo.pdf ;

output/naboj/%: \
output/naboj/%/languages ;
# All targets for all venues
# <competition>/<volume>
output/naboj/%/venues: \
$$(foreach dir,$$(subst source/,output/,$$(wildcard source/naboj/$$*/venues/*)),$$(dir)) ;

output/naboj/%/all: \
output/naboj/%/languages \
output/naboj/%/venues ;

output/naboj/%/copy: \
output/naboj/%
Expand Down
9 changes: 6 additions & 3 deletions modules/naboj/templates/answers-modulo.jtt
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@

\section{(* i18n[language.id].section.answers *)}
\pagestyle{answers}
\protectedInput{\rootDirectory/(* module.id *)/(* competition.id *)/(* volume.id *)/venues/(* venue.id *)/evaluators.tex}
\protectedInput{\rootDirectory/(* module.id *)/(* competition.id *)/(* volume.id *)/languages/(* venue.language *)/evaluators.tex}

(@ for modulo in venue.problems_modulo @)
\newpage%
\newpage
\section{(* i18n[language.id].section.modulo *) (* loop.index0 *)}
(@ for problem in modulo @)%
(@ for problem in modulo @)
(@ include 'answer.jtt' @)
(@ endfor @)

(@ endfor @)

(@ endblock @)
13 changes: 13 additions & 0 deletions modules/naboj/templates/evaluation.jtt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
(@ extends 'base-booklet.jtt' @)

(@ block content @)
\fancypagestyle{instructions}{%
\pagestyle{naboj}
\fancyhead[LE,RO]{\textit{(* i18n[language.id].instructions.title *)}}
\fancyfoot[C]{}
}
\pagestyle{instructions}

\section{(* i18n[language.id].instructions.title *)}
\input{build/(* module.id *)/(* competition.id *)/(* volume.id *)/languages/(* language.id *)/evaluators.tex}
(@ endblock @)
6 changes: 0 additions & 6 deletions modules/naboj/templates/tearoff/bottom.jtt
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,3 @@
\LARGE
\textit{(* i18n[language.id].tearoff.bottom *)}
(@ endblock main @)

(@ block probnum2 @)(* '%02d'|format(0) *)(@ endblock probnum2 @)

(@ block checkdigit @)(* '%01d'|format(checkdigit(team.code, 0)) *)(@ endblock checkdigit @)

(@ block page @)(* (team.number + 1) * (volume.problems|length + 1) *)(@ endblock page @)
4 changes: 2 additions & 2 deletions modules/naboj/templates/tearoff/problem.jtt
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
(@ endblock activate @)

\begin{minipage}[t][(* competition.tearoff.height *)mm][t]{\textwidth}%
\begin{minipage}[t][(* competition.tearoff.inner *)mm][t]{0.85\linewidth}%
\begin{minipage}[t][(* competition.tearoff.inner *)mm][t]{0.86\linewidth}%
(@ block main @)
\vspace{0pt}%
\subsection{\texorpdfstring{(* problem.number *)}{(* language.id *): (* problem.number *). (* problem.id *)}}%
\setlength{\parskip}{6pt}
\protectedInput{\activeDirectory/(* language.id *)/problem.tex}%
(@ endblock main @)
\end{minipage}%
\begin{minipage}[t][(* competition.tearoff.inner *)mm][t]{0.149\linewidth}
\begin{minipage}[t][(* competition.tearoff.inner *)mm][t]{0.139\linewidth}
\vspace{0mm}%
\hspace{4mm}%
\rotatebox{90}{%
Expand Down

0 comments on commit 9e8ef76

Please sign in to comment.