add tag
JeT
**Context**

My target is to have a simple way to toggle between `(beamer)article` and `beamer` and produce multiple pdf formats. 

Ultimately (I am almost there), I'd like to 
- fill a simple file of parameters (pgfkeys) (could be a very long list)
- launch a batch file gobbling these parameters to produce after compilation(s)
	- Notes in `article` mode 
	- Slides in `beamer`
	- Slides in 2x1 mode (in case some students want to print their slides) with  		
    	
        `\usepackage{pgfpages}`
        
		`\pgfpagesuselayout{2 on 1}[a4paper,border shrink=2mm] `
	- any other variation available in the keys.  

**My question(s)**

1. I struggle with `pgfkeys` and use probably too many `if` to define what should be for both `beamerarticle` and `beamer` or specific to one of each.
2. Marmot suggested there was a way to include the `pgfkeys` in the batch.
3. Don't know whether I should use this batch method or `arara` or `latexmk` that are faaaar from my level of understanding so far...


**Questions already answered to build my question**

> **What `\documentclass` to load ?**

 Define whether I should load `article` or `beamer`
 
 https://tex.stackexchange.com/questions/1492/passing-parameters-to-a-document 

No alternative right ?

```
\if 0\model
  \documentclass[...]{article}
   \usepackage[envcountsect]{beamerarticle}  
\fi

\if 1\model
  \documentclass{beamer}
\fi
```

> **Definition of pgfkeys**

How to use pgfkeys to (elegantly) parameter my document (from which I take a modified MWE.)
https://topanswers.xyz/tex?q=1375


> **Batch to create the different contents**

I finally create a `batch.bat` that will produce 2 versions but i'd like to pass pgfkeys here, to have the flexibility to produce more outputs.

For instance, to pass
```
\usepackage{pgfpages}
\pgfpagesuselayout{n on 1}[a4paper,border shrink=2mm]
```
to produce a pdf with `n` slides per page.

So far this seems to work to create the `beamer` and `article` version.

```
pdflatex -synctex=1 -interaction=nonstopmode --shell-escape  "\def\model{0}\input{"MWE.tex"}" --jobname=MWE_article
pdflatex -synctex=1 -interaction=nonstopmode --shell-escape  "\def\model{1}\input{"MWE.tex"}" --jobname=MWE_beamer
del /s *.aux *.log *.gz *.out *.nav *.snm *.vrb *.bbl *.synctex(busy) *.synctex.gz  *.defs *.loe *.lot *.lof *.dep *.toc *.xtr
```

The batch will compile the following document.

```
------           MWE.tex           ----------
\def\model{1}		% I have to turn that off if I use MWE in the batch. (

\if 0\model 
\documentclass{article}
\usepackage{beamerarticle}
\fi

\if 1\model 
\documentclass{beamer}
\fi

%% I use 3 different preambles to store the keys and it does not seem right.

\begin{filecontents}[overwrite]{preambleJeT.sty}
\RequirePackage{pgfopts}	

\pgfkeys{/JeT/.cd,
		common/.cd,
			author/.code={\author{#1}},
			author/.default={JeT},			
			title/.code={\title{#1}},
			subtitle/.code={\subtitle{#1}},
			institute/.code={\institute{#1}},
			institute/.default={Univeristy},			
		standard/.style={
			author,
			title={Course title},
			subtitle=Session 1,
			institute,
			}	 
}	
\ProcessPgfOptions{/JeT/common}
\end{filecontents}

\if 0\model

\begin{filecontents}[overwrite]{beamerpreambleJeT.sty}
\RequirePackage{pgfopts}	
\pgfkeys{/JeT/.cd,
		beamer/.cd,
			theme/.code={\usetheme{#1}},
			colortheme/.code={\usecolortheme{#1}},
		standard-beamer/.style={
			theme={CambridgeUS},
			colortheme=crane,
			}	 
}	
\ProcessPgfOptions{/JeT/beamer}

\end{filecontents}
\fi

\if 1\model
\begin{filecontents}[overwrite]{articlepreambleJeT.sty}
\RequirePackage{pgfopts}	

\pgfkeys{/JeT/.cd,
		article/.cd,
			font/.is choice,
				font/fourier/.code={
					\usepackage{fourier}
					\usepackage[scaled=0.875]{helvet} 
					\renewcommand{\ttdefault}{lmtt}},
			font/Latin-Modern/.code={
				\usepackage{lmodern}
				\usepackage[T1]{fontenc}},			
			font/.default ={fourier},				
		standard/.style={
			font
			}	 
}	
\ProcessPgfOptions{/JeT/article}
\end{filecontents}
\fi

\usepackage[standard,author={JeTov}]{preambleJeT}

\if 0\model 
\usepackage[standard]{articlepreambleJeT}	
\fi
\if 1\model 
\usepackage[standard-beamer,theme={Hannover}]{beamerpreambleJeT} 
\fi

\begin{filecontents}[overwrite]{main.tex}
\maketitle

\begin{frame}[t]
	\frametitle{Pft}
	This is a test.
\end{frame}
\end{filecontents}


\begin{document}

\input{main}

\end{document}
```
Top Answer
user 3.14159
Big thanks go to @Skillmon for teaching me what `\RequirePackage` is good for, and to frougon for suggesting a [better expansion of the pgf keys](https://topanswers.xyz/transcript?room=1437&id=74522#c74522). 

With the code below you can use calls like
```
pdflatex -synctex=1 -interaction=nonstopmode --shell-escape  "\def\mykeys{standard,author={JeTov}}\input{MWE.tex}" --jobname=MWE_beamer
```
to compile the document. The important piece is `\def\mykeys{standard,author={JeTov}}` which sets a bunch of pgf keys that get worked through. You need to be a bit careful about the order, the class has to come first. That is, in 
```
standard/.style={/JeT/common/.cd,
			class=presentation,%<- has to be set and come first
			author,
			title={Course title},
			subtitle=Session 1,
			institute,
			}
```
you cannot move the class below the other keys. Other keys may be ordered appropriately, too. I also decided to work with plain pgf to allow for spaces in the keys. While the need to order things is a bit cumbersome, perhaps, on the bright side you can make your own sanity checks when trying to load packages and themes, and can suppress them when it does not make sense. As before, the stuff within filecontents is just there to make the answer self-contained, in the real use case you just have a separate file. Altogether I see some benefits of this approach but am also looking forward to seeing alternatives. In particular you may combine this with the pgf-based lecture collections under [an earlier thread of yours](https://topanswers.xyz/tex?q=1348). 

```
\begin{filecontents}[overwrite]{mypreambleJeT.sty}
\RequirePackage{pgf}
\pgfkeys{/JeT/.cd,
	standard/.style={/JeT/common/standard}}	
\pgfkeys{/JeT/.cd,
		common/.cd,
			author/.code={\author{#1}},
			author/.default={JeT},			
			title/.code={\title{#1}},
			subtitle/.code={\subtitle{#1}},
			institute/.code={\institute{#1}},
			institute/.default={University},			
		class/.is choice,
		class/article/.code={%
		     \documentclass{article}
			 \usepackage{beamerarticle}
			 \edef\JeT@imodel{0}%
		},
		class/presentation/.code={%
			\documentclass{beamer}
			\edef\JeT@imodel{1}%	
		},
		standard/.style={/JeT/common/.cd,
			class=presentation,%<- has to be set and come first
			author,
			title={Course title},
			subtitle=Session 1,
			institute,
			}	 
}
\pgfkeys{/JeT/.cd,
		beamer/.cd,
			theme/.code={\ifnum\JeT@imodel=1
			\usetheme{#1}
			\else
			\typeout{The theme selection only makes sense for beamer documents.}
			\fi},
			colortheme/.code={\ifnum\JeT@imodel=1
			\usecolortheme{#1}
			\else
			\typeout{The color theme selection only makes sense for beamer documents.}
			\fi},
		standard-beamer/.style={/JeT/beamer/.cd,
			theme={CambridgeUS},
			colortheme=crane,
			}	 
}	
\pgfkeys{/JeT/.cd,
		article/.cd,
			font/.is choice,
			font/fourier/.code={\ifnum\JeT@imodel=0
				\usepackage{fourier}
				\usepackage[scaled=0.875]{helvet} 
				\renewcommand{\ttdefault}{lmtt}
				\else
				\typeout{The article font selection only makes sense for article documents.}
				\fi},
			font/Latin-Modern/.code={\ifnum\JeT@imodel=0
				\usepackage{lmodern}
				\usepackage[T1]{fontenc}
				\else
				\typeout{The article font selection only makes sense for article documents.}
				\fi},			
			font/.default ={fourier},				
		standard/.style={/JeT/article/.cd,
			font=fourier
			}	 
}	
\ifdefined\mykeys
\begingroup
  \toks@=\expandafter{\mykeys}%
  \edef\temp{\noexpand\pgfkeys{/JeT/.cd,\the\toks@}}%
  \expandafter
\endgroup
\temp
\fi	
\end{filecontents}%
% here starts the real document
\RequirePackage{mypreambleJeT}
\begin{document}
\maketitle

\begin{frame}[t]
	\frametitle{Pft}
	This is a test.
\end{frame}
\end{document}
```

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.