Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion problemtools/statement_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ def load_names_from_statements(problem_root: Path, version: FormatVersion) -> di
assert version is FormatVersion.LEGACY, 'load_names_from_statements only makes sense for legacy format'
ret: dict[str, str] = {}
for lang, files in find_statements(problem_root, version).items():
hit = re.search(r'\\problemname{(.*)}', files[0].read_text(), re.MULTILINE)
text = files[0].read_text()
flags = re.MULTILINE
# Two separate searches, as we want plainproblemname to override problemname if both exist.
hit = re.search(r'^%%\s*plainproblemname:(.*)$', text, flags) or re.search(r'\\problemname{(.*)}', text, flags)
if hit:
ret[lang] = hit.group(1).strip()
return ret
Expand Down
5 changes: 5 additions & 0 deletions problemtools/verifyproblem.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,9 @@ def check(self, context: Context) -> bool:
f'No problem statements found (expected file of one of following forms in directory {self.problem.format.statement_directory}/: {allowed_statements})'
)

def _latex_heuristic(name: str) -> bool:
return '\\' in name or '$' in name

for lang, files in self.statements.items():
if len(files) > 1:
self.error(f'Found multiple statements in the same language {lang}: {", ".join((file.name for file in files))}')
Expand All @@ -849,6 +852,8 @@ def check(self, context: Context) -> bool:
self.error(f'Problem name in language {lang} is empty')
elif not self.problem.metadata.name[lang].strip():
self.error(f'Problem name in language {lang} contains only whitespace')
elif self.problem.format is FormatVersion.LEGACY and _latex_heuristic(self.problem.metadata.name[lang]):
self.warning(f'Problem name in language {lang} looks like LaTeX. Consider using plainproblemname.')

for file in files:
try:
Expand Down
3 changes: 2 additions & 1 deletion tests/hello/problem_statement/problem.sv.tex
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
\problemname{Hej Världen!}
\problemname{Hej V\"arlden!} % Silly use of LaTeX just to test plainproblemname
%% plainproblemname: Hej Världen!

\section*{Indata}

Expand Down