JeT
The answer https://topanswers.xyz/tex?q=583 finally enabled me to understand better Latexmk structure and synthax. I did my homework and applied, it works great. However, my current synthax makes me think there is an automated next step.
Thanks to https://topanswers.xyz/tex?q=1375, I learned how to pass parameters to a documents with `pgfkeys`.
https://manpages.debian.org/testing/latexmk/latexmk.1.en.html is clear but I don't manage to apply.
**Context**
I have one course ABC101 and I need several compilations (merci `latexmk`) to produce different outputs for
- different audience
- stud(ents)
- prof
- different formats
- notes
- beamer
- different pagelayouts (single or multipage)
- mono
- multi
The (working) result is the horrible (3yo level) code below.
There is a better way...
**My question**
How do I reach something like
```
Maindocument = MWE.tex
Course = ABC101
Audience = {prof,stud}
Format = {notes,beamer}
Pagelayouts = {mono,multi}
Compilationmode = pdflatex -synctex=1 -interaction=nonstopmode -shell-escape
latexmk -pdf -pdflatex="Compilationmode" -jobname=Course_Audience_Format_Pagelayouts -pretex="\def\mykeys{format={Course}{Format}{Audience}{Pagelayouts}}" -usepretex MWE
```
rather than this horrible...
```
latexmk -pdf -pdflatex="pdflatex -synctex=1 -interaction=nonstopmode -shell-escape" -jobname=ABC101Lec1_notes_prof_mono -pretex="\def\mykeys{format={ABC101}{notes}{prof}{mono}}" -usepretex MWE
latexmk -pdf -pdflatex="pdflatex -synctex=1 -interaction=nonstopmode -shell-escape" -jobname=ABC101Lec1_notes_prof_multi -pretex="\def\mykeys{format={ABC101}{notes}{prof}{multi}}" -usepretex MWE
latexmk -pdf -pdflatex="pdflatex -synctex=1 -interaction=nonstopmode -shell-escape" -jobname=ABC101Lec1_notes_stud_mono -pretex="\def\mykeys{format={ABC101}{notes}{stud}{mono}}" -usepretex MWE
latexmk -pdf -pdflatex="pdflatex -synctex=1 -interaction=nonstopmode -shell-escape" -jobname=ABC101Lec1_notes_stud_multi -pretex="\def\mykeys{format={ABC101}{notes}{stud}{multi}}" -usepretex MWE
latexmk -pdf -pdflatex="pdflatex -synctex=1 -interaction=nonstopmode -shell-escape" -jobname=ABC101Lec1_beamer_prof_mono -pretex="\def\mykeys{format={ABC101}{beamer}{prof}{mono}}" -usepretex MWE
latexmk -pdf -pdflatex="pdflatex -synctex=1 -interaction=nonstopmode -shell-escape" -jobname=ABC101Lec1_beamer_stud_mono -pretex="\def\mykeys{format={ABC101}{beamer}{stud}{mono}}" -usepretex MWE
```
**Edit**
https://tex.stackexchange.com/questions/29671/how-to-configure-latexmk-to-work-recursively-pdf-thumbnails gives me an idea of what I'm looking for.
Top Answer
samcarter
One possibility would be to script this. Here an example using a small lua file which can be executed with
```bash
lua filename.lua
```
---
```lua
Maindocument = "MWE.tex"
Course = "ABC101"
Audience = {"prof","stud"}
Format = {"notes","beamer"}
Pagelayouts = {"mono","multi"}
Compilationmode = "pdflatex -synctex=1 -interaction=nonstopmode -shell-escape"
for Audience_key,Audience_value in ipairs(Audience) do
for Format_key,Format_value in ipairs(Format) do
for Pagelayouts_key,Pagelayouts_value in ipairs(Pagelayouts) do
os.execute(
"latexmk -pdf -pdflatex=\""
.. Compilationmode
.. "\" -jobname="
.. Course
.. "Lec1_"
.. Format_value
.. "_"
.. Audience_value
.. "_"
.. Pagelayouts_value
.. " -pretex=\"\\def\\Cours{"
.. Course
.. "}\\def\\Lec{1}\\def\\mykeys{format={"
.. Course
.. "}{"
.. Format_value
.. "}{"
.. Audience_value
.. "}{"
.. Pagelayouts_value
.. "}}\" -usepretex "
.. Maindocument
.. " \n"
)
end
end
end
```