I want to set one argument of a function permanently to a specific value.
In my case it is the function \TextField which has the argument bordercolor. I want to set it globally to "nothing" instead of writing \TextField[bordercolor=,name=xyz] everytime.
This was my attempt which leads to an error:
\renewcommand{\TextField}{\TextField[bordercolor=]}
Asked
Active
Viewed 279 times
2
TobiSonne
- 271
2 Answers
2
\documentclass{article}
\usepackage{xcolor}
\usepackage{hyperref}
\let\TEXTFIELD\TextField
\renewcommand\TextField[1][]{\TEXTFIELD[bordercolor=,#1]}
\begin{document}
\begin{Form}
\TextField[name=xy]{foo}
\TextField[bordercolor=red,name=xy]{bar}
\end{Form}
\end{document}
user187802
- 16,850
2
hyperref has a command to which you can append default keys for the textfield (by default it contains only "print"):
\documentclass{article}
\usepackage{xcolor}
\usepackage{hyperref}
\usepackage{etoolbox}
\apptocmd\DefaultOptionsofText{,bordercolor=}{}{\fail}
\begin{document}
\begin{Form}
\TextField[name=xy]{foo}
\TextField[bordercolor=red,name=xy]{bar}
\end{Form}
\end{document}
The alternative is to simply set the key with \kvsetkeys (this will affect the border of other field types too):
\documentclass{article}
\usepackage{xcolor}
\usepackage{hyperref}
\begin{document}
\begin{Form}
\kvsetkeys{Field}{bordercolor=}
\TextField[name=x]{foo}
\TextField[bordercolor=red,name=y]{bar}
\end{Form}
\end{document}
Ulrike Fischer
- 327,261

\TextField. We need it to prevent a recursion. – user187802 Aug 06 '19 at 12:28\TextFieldis defined with\DeclareRobustCommand,\let\TEXTFIELD\TextFieldis dangerous. Load\usepackage{letltxmacro}and do\LetLtxMacro\TEXTFIELD\TextFieldinstead. See When to use\LetLtxMacro. – egreg Aug 06 '19 at 12:55