-
Notifications
You must be signed in to change notification settings - Fork 22
Description
Aside about
\constant{name}in LaTeX:What we seem to want to support is a mechanism for the Latex source to refer to values defined in
problem.yaml. I clean way to do that (which would require minimal effort do define) is\problem{foo}wherefoois a key inproblem.yaml.@thorehusfeldt This is a new (and novel) idea. I'm not sure at all if I like it or not, but I think it should be a separate issue. Was this a real suggestion, or more of a random thought? If the former, we should create a new issue for it.
I will close this issue now though.
Originally posted by @niemela in #344
Continuing this line of thought.
Several mechanisms in the problem package want access to values in problem.yaml. Here are just three, different, examples:
input_validator/validate/wants to knowconstants.max_n.value- the LaTeX problem statement to know
title.en
We currently have different ways of facilitating this, such as LaTeX macros and template substitution. But we can’t do this:
from bapctoolslib import problem # imaginary module that just parses ../../problem.yaml and puts it into a useful namespace
max_n = problem.constants.max_n # OMG! No substitution! The linter is happy! I can run my code from CLIOr, without a library,
from ruamel.yaml import YAML
yaml = YAML(typ="safe") # safe loader -> plain Python types
with open("../problem.yaml", "r") as f:
prroblem = yaml.load(f)
max_n = problem.constants.max_n
Whatever mechanism a language or framework uses to open a YAML file can be used. No substitution is performed. If BAPCtools wants to write neat libraries or .h header files that hide the YAML parsing, they can do that. Or not. A LaTeX class file would do the same. Or an upcoming typst library for making really sexy solution slides that read problem.source. (Alas, YAML can’t include YAML, otherwise that would be perfect.)
The only change to the specification is for sandboxing:
- the
problem.yamlmust be is available to the code in the same relative position as in the problem package.