Skip to content

Commit b6a161f

Browse files
authored
Merge pull request #360 from gkreitz/356_repair_plainproblemname
Add back support for plainproblemname
2 parents 5518a20 + 8ec14a4 commit b6a161f

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

problemtools/statement_util.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ def load_names_from_statements(problem_root: Path, version: FormatVersion) -> di
4747
assert version is FormatVersion.LEGACY, 'load_names_from_statements only makes sense for legacy format'
4848
ret: dict[str, str] = {}
4949
for lang, files in find_statements(problem_root, version).items():
50-
hit = re.search(r'\\problemname{(.*)}', files[0].read_text(), re.MULTILINE)
50+
text = files[0].read_text()
51+
flags = re.MULTILINE
52+
# Two separate searches, as we want plainproblemname to override problemname if both exist.
53+
hit = re.search(r'^%%\s*plainproblemname:(.*)$', text, flags) or re.search(r'\\problemname{(.*)}', text, flags)
5154
if hit:
5255
ret[lang] = hit.group(1).strip()
5356
return ret

problemtools/verifyproblem.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,9 @@ def check(self, context: Context) -> bool:
840840
f'No problem statements found (expected file of one of following forms in directory {self.problem.format.statement_directory}/: {allowed_statements})'
841841
)
842842

843+
def _latex_heuristic(name: str) -> bool:
844+
return '\\' in name or '$' in name
845+
843846
for lang, files in self.statements.items():
844847
if len(files) > 1:
845848
self.error(f'Found multiple statements in the same language {lang}: {", ".join((file.name for file in files))}')
@@ -850,6 +853,8 @@ def check(self, context: Context) -> bool:
850853
self.error(f'Problem name in language {lang} is empty')
851854
elif not self.problem.metadata.name[lang].strip():
852855
self.error(f'Problem name in language {lang} contains only whitespace')
856+
elif self.problem.format is FormatVersion.LEGACY and _latex_heuristic(self.problem.metadata.name[lang]):
857+
self.warning(f'Problem name in language {lang} looks like LaTeX. Consider using plainproblemname.')
853858

854859
for file in files:
855860
try:

tests/hello/problem_statement/problem.sv.tex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
\problemname{Hej Världen!}
1+
\problemname{Hej V\"arlden!} % Silly use of LaTeX just to test plainproblemname
2+
%% plainproblemname: Hej Världen!
23

34
\section*{Indata}
45

0 commit comments

Comments
 (0)