Feat: add Integer and Decimal in mapytex_tools
This commit is contained in:
parent
de8d3e574d
commit
f5f9e9193f
@ -12,10 +12,10 @@ import sys
|
||||
|
||||
from path import Path
|
||||
import pytex
|
||||
from mapytex import Expression
|
||||
from mapytex import Expression, Integer, Decimal
|
||||
import bopytex.filters as filters
|
||||
|
||||
formatter = logging.Formatter('%(name)s :: %(levelname)s :: %(message)s')
|
||||
formatter = logging.Formatter("%(name)s :: %(levelname)s :: %(message)s")
|
||||
steam_handler = logging.StreamHandler()
|
||||
steam_handler.setLevel(logging.DEBUG)
|
||||
steam_handler.setFormatter(formatter)
|
||||
@ -29,6 +29,8 @@ def setup():
|
||||
logger.debug(f"Render for Expression is {Expression.RENDER}")
|
||||
mapytex_tools = {
|
||||
"Expression": Expression,
|
||||
"Integer": Integer,
|
||||
"Decimal": Decimal,
|
||||
# "Polynom": mapytex.Polynom,
|
||||
# "Fraction": mapytex.Fraction,
|
||||
# "Equation": mapytex.Equation,
|
||||
@ -50,24 +52,25 @@ def get_working_dir(options):
|
||||
try:
|
||||
template = Path(options.template)
|
||||
except TypeError:
|
||||
raise ValueError("Need to set the working directory \
|
||||
or to give a template")
|
||||
raise ValueError(
|
||||
"Need to set the working directory \
|
||||
or to give a template"
|
||||
)
|
||||
else:
|
||||
working_dir = template.dirname()
|
||||
logger.debug(f"The output directory will be {working_dir}")
|
||||
return working_dir
|
||||
|
||||
|
||||
def activate_printanswers(texfile):
|
||||
def activate_printanswers(
|
||||
texfile, noans=r"solution/print = false", ans=r"solution/print = true"
|
||||
):
|
||||
""" Activate printanswers mod in texfile """
|
||||
output_fname = "corr_" + texfile
|
||||
with open(texfile, 'r') as input_f:
|
||||
with open(texfile, "r") as input_f:
|
||||
with open(output_fname, "w") as output_f:
|
||||
for line in input_f.readlines():
|
||||
output_f.write(line.replace(
|
||||
r'solution/print = false',
|
||||
r'solution/print = true',
|
||||
))
|
||||
output_f.write(line.replace(noans, ans))
|
||||
return output_fname
|
||||
|
||||
|
||||
@ -109,25 +112,14 @@ def produce_and_compile(options):
|
||||
template = Path(options.template).name
|
||||
logger.debug(f"Template will be {template}")
|
||||
|
||||
list_infos = [
|
||||
{"num": f"{i+1:02d}"}
|
||||
for i in range(options.num_subj)
|
||||
]
|
||||
list_infos = [{"num": f"{i+1:02d}"} for i in range(options.num_subj)]
|
||||
|
||||
tex_files = []
|
||||
for infos in list_infos:
|
||||
dest = (
|
||||
working_dir
|
||||
/ Path(template.replace("tpl", infos["num"]))
|
||||
)
|
||||
dest = working_dir / Path(template.replace("tpl", infos["num"]))
|
||||
logger.debug(f"Feeding template toward {dest}")
|
||||
tex_files.append(dest)
|
||||
pytex.feed(
|
||||
working_dir/template,
|
||||
{"infos": infos},
|
||||
output=dest,
|
||||
force=1
|
||||
)
|
||||
pytex.feed(working_dir / template, {"infos": infos}, output=dest, force=1)
|
||||
logger.debug(f"{dest} fed")
|
||||
|
||||
if not options.no_compil:
|
||||
@ -142,9 +134,9 @@ def produce_and_compile(options):
|
||||
if not options.no_join and not options.no_compil:
|
||||
pdfjoin(
|
||||
pdf_files,
|
||||
template.replace('tpl', "all").replace(".tex",".pdf"),
|
||||
template.replace("tpl", "all").replace(".tex", ".pdf"),
|
||||
working_dir,
|
||||
rm_pdfs=1
|
||||
rm_pdfs=1,
|
||||
)
|
||||
|
||||
if options.corr:
|
||||
@ -161,9 +153,9 @@ def produce_and_compile(options):
|
||||
if not options.no_join and not options.no_compil:
|
||||
pdfjoin(
|
||||
pdf_files,
|
||||
template.replace('tpl', "corr").replace(".tex",".pdf"),
|
||||
template.replace("tpl", "corr").replace(".tex", ".pdf"),
|
||||
working_dir,
|
||||
rm_pdfs=1
|
||||
rm_pdfs=1,
|
||||
)
|
||||
|
||||
if not options.dirty:
|
||||
@ -180,7 +172,7 @@ def main():
|
||||
action="store",
|
||||
type="string",
|
||||
dest="template",
|
||||
help="File with the template. The name should have the following form tpl_... ."
|
||||
help="File with the template. The name should have the following form tpl_... .",
|
||||
)
|
||||
parser.add_option(
|
||||
"-w",
|
||||
@ -188,7 +180,7 @@ def main():
|
||||
action="store",
|
||||
type="string",
|
||||
dest="working_dir",
|
||||
help="Where fed templates and compiled files will be placed"
|
||||
help="Where fed templates and compiled files will be placed",
|
||||
)
|
||||
parser.add_option(
|
||||
"-N",
|
||||
@ -197,42 +189,42 @@ def main():
|
||||
type="int",
|
||||
dest="num_subj",
|
||||
default=1,
|
||||
help="The number of subjects to make"
|
||||
help="The number of subjects to make",
|
||||
)
|
||||
parser.add_option(
|
||||
"-d",
|
||||
"--dirty",
|
||||
action="store_true",
|
||||
dest="dirty",
|
||||
help="Do not clean after compilation"
|
||||
help="Do not clean after compilation",
|
||||
)
|
||||
parser.add_option(
|
||||
"-n",
|
||||
"--no-compile",
|
||||
action="store_true",
|
||||
dest="no_compil",
|
||||
help="Do not compile source code"
|
||||
help="Do not compile source code",
|
||||
)
|
||||
parser.add_option(
|
||||
"-j",
|
||||
"--no-join",
|
||||
action="store_true",
|
||||
dest="no_join",
|
||||
help="Do not join pdf and clean single pdf"
|
||||
help="Do not join pdf and clean single pdf",
|
||||
)
|
||||
parser.add_option(
|
||||
"-O",
|
||||
"--only-corr",
|
||||
action="store_true",
|
||||
dest="only_corr",
|
||||
help="Create and compile only correction from existing subjects"
|
||||
help="Create and compile only correction from existing subjects",
|
||||
)
|
||||
parser.add_option(
|
||||
"-c",
|
||||
"--corr",
|
||||
action="store_true",
|
||||
dest="corr",
|
||||
help="Create and compile correction while making subjects"
|
||||
help="Create and compile correction while making subjects",
|
||||
)
|
||||
|
||||
(options, _) = parser.parse_args()
|
||||
@ -246,7 +238,7 @@ def main():
|
||||
produce_and_compile(options)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user