diff --git a/bopytex/default_config.py b/bopytex/default_config.py index 4619b82..a4444d5 100644 --- a/bopytex/default_config.py +++ b/bopytex/default_config.py @@ -1,6 +1,6 @@ -#import jinja2 as j2 from bopytex.planner.generate_compile_join_planner import planner from bopytex.worker import Dispatcher +from bopytex.worker.activate_corr import activate_corr from bopytex.worker.clean import clean from bopytex.worker.compile import pdflatex from bopytex.worker.generate import generate @@ -8,12 +8,19 @@ from bopytex.worker.join_pdf import pdfjam from bopytex.jinja2_env.texenv import texenv jinja2 = { - # "environment": j2.Environment(loader=j2.FileSystemLoader("./")), "environment": texenv } -dispatcher = Dispatcher( - {"GENERATE": generate, "COMPILE": pdflatex, "JOIN": pdfjam, "CLEAN": clean} -) +dispatcher = Dispatcher({ + "GENERATE": generate, + "COMPILE": pdflatex, + "JOIN": pdfjam, + "CLEAN": clean, + "ACTIVATE_CORR": activate_corr, + }) +latex = { + "solution": r"solution/print = true", + "no_solution": r"solution/print = false", + } diff --git a/bopytex/planner/activate_corr_compile_join_planner.py b/bopytex/planner/activate_corr_compile_join_planner.py index a67c20f..0e84e68 100644 --- a/bopytex/planner/activate_corr_compile_join_planner.py +++ b/bopytex/planner/activate_corr_compile_join_planner.py @@ -1,4 +1,4 @@ -from bopytex.tasks import Task, activate_corr_on, compile_pdf, generate, join_pdfs +from bopytex.tasks import Task, activate_corr_on, compile_pdf, join_pdfs import bopytex.planner.naming as naming import os diff --git a/bopytex/planner/generate_compile_join_planner.py b/bopytex/planner/generate_compile_join_planner.py index 8fd2ad2..27104c8 100644 --- a/bopytex/planner/generate_compile_join_planner.py +++ b/bopytex/planner/generate_compile_join_planner.py @@ -80,7 +80,7 @@ def tasks_builder( if corr: corr_source = naming.corr(source) - tasks.append(activate_corr_on(source, corr_source)) + tasks.append(activate_corr_on(source, opt, corr_source)) if not no_pdf: corr_pdf = naming.source2pdf(corr_source) diff --git a/bopytex/tasks.py b/bopytex/tasks.py index 5244f20..d0f3287 100644 --- a/bopytex/tasks.py +++ b/bopytex/tasks.py @@ -24,11 +24,11 @@ def generate(template: str, meta: dict, output: str): ) -def activate_corr_on(src: str, output: str): +def activate_corr_on(src: str, meta:dict, output: str): """Create a task to activate correction for src""" return Task( action="ACTIVATE_CORR", - args={}, + args=meta, deps=[src], output=output, ) diff --git a/bopytex/worker/activate_corr.py b/bopytex/worker/activate_corr.py new file mode 100644 index 0000000..3f300a2 --- /dev/null +++ b/bopytex/worker/activate_corr.py @@ -0,0 +1,14 @@ +from bopytex.message import Message + + +def activate_corr(args, deps, output): + no_solution = args["latex"]["no_solution"] + solution = args["latex"]["solution"] + + with open(deps[0], "r") as input_f: + with open(output, "w") as output_f: + for line in input_f.readlines(): + output_f.write(line.replace(no_solution, solution)) + + return Message(0, [f"ACTIVATE CORR - {deps[0]} to {output}"], []) + diff --git a/example/usecase/joined_example.pdf b/example/usecase/joined_example.pdf index 1200dcd..fb2fd5d 100644 Binary files a/example/usecase/joined_example.pdf and b/example/usecase/joined_example.pdf differ diff --git a/example/usecase/tpl_example.tex b/example/usecase/tpl_example.tex index 48b3339..d5a90bc 100644 --- a/example/usecase/tpl_example.tex +++ b/example/usecase/tpl_example.tex @@ -4,6 +4,8 @@ \title{Bopytex with Mapytex example -- \Var{ number }} +% solution/print = false + \begin{document} \maketitle