TeX - LaTeX Asked on April 21, 2021
The problem is as follows: I need to pass the same set of options (say angle=90, scale=0.85
) to a given command (say includepdf
) repeatedly. One approach is to save that option in some macro, say __Foo
. The problem is includepdf[__Foo]
causes an error. I have proposed two ways to solve it, one with expandafter
, another with a custom function to be invoked with the command and the option. Neither of which satisfy me. Is there there a tool (in etoolbox?) to create a new function from includepdf
, say includepdfbis
, such that I can use it like this: includepdfbis[__Foo]
?
documentclass{article}
usepackage{mwe}
usepackage{pdfpages}
usepackage{xparse}
ExplSyntaxOn
def__Foo{angle=90, scale=0.85}
cs_new_protected:Nn__erw_pass_option:Nn{#1[#2]}
cs_generate_variant:Nn __erw_pass_option:Nn {Ne}
ExplSyntaxOff
begin{document}
ExplSyntaxOn
%includepdf[__Foo]{example-image-a} % ERROR: Package keyval Error: angle=90,scale=0.85 undefined.
expandafterincludepdfexpandafter[__Foo]{example-image-a}
__erw_pass_option:Ne includepdf{__Foo}{example-image-a}
ExplSyntaxOff
end{document}
As it is harmless to apply expandafter to the filename if no option is used, you can just unconditionally use the form you showed but wrapped in a macro.
documentclass{article}
usepackage{pdfpages}
% you would need expl3 package in older latex releases.
ExplSyntaxOn
def__Foo{angle=90, scale=0.85}
% def not really the expl3 way but as you started..
defincludepdfbis{expandafterincludepdfexpandafter}
ExplSyntaxOff
begin{document}
ExplSyntaxOn
includepdfbis[__Foo]{example-image-a}
ExplSyntaxOff
end{document}
Correct answer by David Carlisle on April 21, 2021
You're better to define your own key.
documentclass{article}
usepackage{pdfpages}
makeatletter
define@key{Gin}{Foo}[]{setkeys{Gin}{angle=90, scale=0.85}}
makeatother
begin{document}
includepdf[Foo]{example-image-a}
end{document}
Answered by egreg on April 21, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP