0

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?

Henri Menke
  • 109,596
cjorssen
  • 10,032
  • 4
  • 36
  • 126
  • 3
    are there any upsides? the time taken to load a package is negligible and if you add it to the format your documents will be incompatible with every other latex installation. – David Carlisle Aug 29 '19 at 16:05
  • The upside is of course that you don't have to type \usepackage{kvoptions-patch} in your documents anymore, if you compile them on your own installation. – Marijn Aug 29 '19 at 16:26
  • @DavidCarlisle As Marijn said, the upside is that I can use key = val inside \documentclass without the need to type \RequirePackage{kvoptions-patch} before \documentclass. – cjorssen Aug 29 '19 at 16:48
  • sure but the price of making your document not a latex document and unusable in any standard latex installation seems far too high a price to pay. – David Carlisle Aug 29 '19 at 16:49
  • 2
    In addition to what @DavidCarlisle says, doing this could effectively prevent you from sharing documents with anyone else. – barbara beeton Aug 29 '19 at 19:25
  • @barbarabeeton it would only prevent sharing documents that actually use key-val options, other documents would be fine. Also it would be trivial to fix the document when it needs to be shared. So there might be a valid use case here as long as the OP understands the consequences. – Marijn Aug 29 '19 at 21:27
  • I would create a new format file based on the latex format 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

1 Answers1

1

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 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.
Marijn
  • 37,699