[texhax] [hyperref] Programatically change the name of the \CheckBox?
Heiko Oberdiek
heiko.oberdiek at googlemail.com
Tue Nov 25 17:47:56 CET 2014
Hello,
On 26.11.2014 12:50, Hubert Lam wrote:
> Hi all
>
>
>
> Does anyone know of ways to programmatically changing the name of the
> \CheckBox?
Yes, it is possible.
> i.e. I would like the name of the \CheckBox to advance with the
> \theenumi counter. However, if I use
>
>
>
> \CheckBox[name=Name\theenumi]{}
>
>
>
> Then it fail to compile, resulting in an error about “Use of \pdfmark@
> doesn’t match its definition”.
The definition of `\theenumi` is not appropriate, in contrary
you have a recursion: "label=\protect\CheckBoxes\arabic*."
defines \theenumi. If \theenumi is called within the \CheckBox,
then it calls \CheckBoxes at the start of the label `\theenumi
and expands further another \CheckBox, which again wants to
have \theenumi in its name.
But you can use the counter value `enumi' instead.
However, \value is redefined, thus \countervalue/\thevalue
are using the original \value:
\documentclass[a4paper,12pt]{article}
\usepackage{calc}
\usepackage{enumitem}
\usepackage{pstricks-add}
\usepackage{hyperref}
\usepackage[margin=1in]{geometry}
\newcommand*{\countervalue}{}
\let\countervalue\value
\newcommand*{\thevalue}{\the\countervalue}
\begin{document}
\newcommand{\Checks}{
\begin{Form}
\CheckBox[name=7N\thevalue{enumi}]{}
\CheckBox[name=7R\thevalue{enumi}]{}
\CheckBox[name=7T\thevalue{enumi}]{}
\CheckBox[name=7H\thevalue{enumi}]{}
\CheckBox[name=7S\thevalue{enumi}]{}
\end{Form}
}
\newcommand{\Placehold}{How are you? }
\newcommand{\CheckBoxes}{%
\begin{minipage}{\widthof{\Checks}}
\Checks
\end{minipage}
}
\begin{flushleft}
\tracingmacros=1
\begin{enumerate}[label={\protect\CheckBoxes \arabic*.},leftmargin=*]
\item \psLoop{15}{\Placehold}
\begin{enumerate}
\item \psLoop{20}{\Placehold}
\item \psLoop{10}{\Placehold}
\item \psLoop{10}{\Placehold}
\item \psLoop{10}{\Placehold}
\end{enumerate}
\item \psLoop{35}{\Placehold}
\end{enumerate}
\end{flushleft}
\end{document}
Yours sincerely
Heiko
More information about the texhax
mailing list