I'm using TeXLive (2019) and I'd like to add a package (namely kvoptions-patch) to all default LaTeX formats. What is the proper way to do this? Is there any downside?
- 109,596
- 10,032
- 4
- 36
- 126
1 Answers
Changing the format is not recommended because it breaks compatibility, as noted in the comments. However, if you still want to use an approach like this, and assuming you use Linux (given the texlive tag) then an easy way to proceed is by using a bash script that automatically loads the package before loading the document itself. The basic idea is to run pdflatex "\RequirePackage{kvoptions-patch}\input{yourfile.tex}" instead of pdflatex yourfile.tex, see for example https://tex.stackexchange.com/a/1495/ for more discussion on this approach. Note that I use pdflatex as an example but it works the same for xelatex and lualatex with the necessary modifications to the script below.
This script should be able to handle command line arguments and insert them in between the command itself and the document string, so you need some bash argument processing in the script.
Furthermore the input as string changes the jobname, i.e., the string that pdflatex uses to create the filename of the output pdf. To use the original filename the command line option --jobname has to be set explicitly.
Finally you can alias the normal compiler command to the script to keep the same workflow as you had before. Put this in your .bashrc to make it permanent.
Script, called myscript.sh:
#!/usr/bin/env bash
function mypdflatex(){
mycmd="\pdflatex --jobname=$(basename "${!#}" .tex) "${*%${!#}}" \"\RequirePackage{kvoptions-patch}\input{${!#}}\""
eval "$mycmd"
}
Load the script and create the alias:
source myscript.sh
alias pdflatex=mypdflatex
Example document kvdummy.tex, that produces an error without kvoptions-patch:
\documentclass[pdfauthor=Fran\c coise M\"uller]{article}
\usepackage{hyperref}
\begin{document}
abc
\end{document}
Compiling the document (shell-escape for illustration only, this is not needed to run the example):
$ pdflatex --shell-escape kvdummy.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.18 (TeX Live 2017/Debian) (preloaded format=pdflatex)
\write18 enabled.
entering extended mode
LaTeX2e <2017-04-15>
Babel <3.18> and hyphenation patterns for 84 language(s) loaded.
(/usr/share/texlive/texmf-dist/tex/latex/oberdiek/kvoptions-patch.sty
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/etexcmds.sty
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/infwarerr.sty)
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/ifluatex.sty)))
(./kvdummy.tex (/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
...
Output written on kvdummy.pdf (1 page, 10434 bytes).
Transcript written on kvdummy.log.
- 37,699
\usepackage{kvoptions-patch}in your documents anymore, if you compile them on your own installation. – Marijn Aug 29 '19 at 16:26key = valinside\documentclasswithout the need to type\RequirePackage{kvoptions-patch}before\documentclass. – cjorssen Aug 29 '19 at 16:48latexformat with that package pre-loaded, see the comments on Is it possible to create a new format file – siracusa Aug 30 '19 at 03:26