这是一个范围问题吗?

这是一个范围问题吗?

我尝试使用该包以 pdf 形式显示精美的评级量表hyperref。经过半天的调查、尝试和错误,我终于有所收获。我使用了一些 documented 和 undocumentedhyperref宏的重新定义(感谢 stackexchange)。

下面的代码

\documentclass[a4paper,12pt]{article}

\usepackage{etoolbox}

\usepackage{hyperref}
\usepackage{tikz}


\newcommand{\radiosize}{1em}
\newcommand{\MakeScaleField}[2]{% label, field
  \begin{tikzpicture}[every node/.style={inner sep=0,outer sep=0, label distance=2mm}]
   \node (chk) {#2};
   \node [anchor=east, label={[blue]left:\radiostart}] (a) at (chk.west) {A};
   \node [anchor=west, label={[blue]right:\radioend}] (b) at (chk.east) {B};
   \path [draw=blue, line width={\radiosize+6pt}, line cap = round] (a) -- (b);
  \end{tikzpicture}
}

\renewcommand{\LayoutChoiceField}[2]{% label, field
 \MakeScaleField{#1}{#2}
}

\newcommand{\formscale}[3]{% name start end
 \def\radiostart{#2}%
 \def\radioend{#3}%
 \let\radiocontent\empty%
   \foreach \i in {\radiostart,...,\radioend} {%
    \gappto\radiocontent{=}%
    \expandafter\gappto\expandafter\radiocontent\expandafter{\i}%
    \ifnum\i<\radioend \gappto\radiocontent{,}\fi%
   }%
 \renewcommand{\DefaultOptionsofRadio}{print,notoggletooff,borderwidth=1pt,bordercolor=white,width=\radiosize,height=\radiosize,bordersep=0pt}%
 \ChoiceMenu[ name=#1, radio, radiosymbol=6 ]{}{\radiocontent}%
}
\begin{document}
\begin{Form}
 This is a scale from 1 to 6 :
 \formscale{Question}{1}{6}
\end{Form}
\end{document}

给了我一个相当令人信服的概念证明:

带有无线电场的尺度

主要警告是此后不能使用默认选择字段。我尝试像使用 一样将 移动到命令\renewcommand{\LayoutChoiceField}中,但失败了。\formscale\renewcommand{\DefaultOptionsofRadio}

代码 :

\documentclass[a4paper,12pt]{article}

\usepackage{etoolbox}

\usepackage{hyperref}
\usepackage{tikz}


\newcommand{\radiosize}{1em}
\newcommand{\MakeScaleField}[2]{% label, field
  \begin{tikzpicture}[every node/.style={inner sep=0,outer sep=0, label distance=2mm}]
   \node (chk) {#2};
   \node [anchor=east, label={[blue]left:\radiostart}] (a) at (chk.west) {A};
   \node [anchor=west, label={[blue]right:\radioend}] (b) at (chk.east) {B};
   \path [draw=blue, line width={\radiosize+6pt}, line cap = round] (a) -- (b);
  \end{tikzpicture}
}


\newcommand{\formscale}[3]{% name start end
 \def\radiostart{#2}%
 \def\radioend{#3}%
 \let\radiocontent\empty%
   \foreach \i in {\radiostart,...,\radioend} {%
    \gappto\radiocontent{=}%
    \expandafter\gappto\expandafter\radiocontent\expandafter{\i}%
    \ifnum\i<\radioend \gappto\radiocontent{,}\fi%
   }%
 \renewcommand{\LayoutChoiceField}[2]{% label, field
  \MakeScaleField{#1}{#2}%
 }%
 \renewcommand{\DefaultOptionsofRadio}{print,notoggletooff,borderwidth=1pt,bordercolor=white,width=\radiosize,height=\radiosize,bordersep=0pt}%
 \ChoiceMenu[ name=#1, radio, radiosymbol=6 ]{}{\radiocontent}%
}
\begin{document}
\begin{Form}
 This is a scale from 1 to 6 :
 \formscale{Question}{1}{6}
\end{Form}
\end{document}

给出这个无用的东西:

没有无线电场的破碎音阶

看起来无线电场不再构建。我尝试了不同的方法,比如\MakeRadioField在我的\formscale命令中重新定义命令,但一无所获。

我不知道这是否是该hyperref软件包所特有的东西,或者我是否错过了一些关于范围的明显的东西。

答案1

在进行一些改进时,我找到了一种使用let而不是 的解决方案renewcommand

我仍然渴望了解为什么我的上述代码失败了

我现在可以在我的命令中保存和恢复修改后的命令\formscale,然后将我的“花式”比例与其他选择字段之王混合。

\documentclass[a4paper,12pt]{article}

\usepackage{etoolbox}

\usepackage{hyperref}
\usepackage{tikz}


\newcommand{\radiosize}{1em}
\newcommand{\MakeScaleField}[2]{% label, field
  \begin{tikzpicture}[every node/.style={inner sep=0,outer sep=0, label distance=2mm}]
   \node (chk) {#2};
   \node [anchor=east, label={[blue]left:\radiostart}] (a) at (chk.west) {A};
   \node [anchor=west, label={[blue]right:\radioend}] (b) at (chk.east) {B};
   \path [draw=blue, line width={\radiosize+6pt}, line cap = round] (a) -- (b);
  \end{tikzpicture}
}


\newcommand{\formscale}[3]{% name start end
 \def\radiostart{#2}%
 \def\radioend{#3}%
 \let\radiocontent\empty%
   \foreach \i in {\radiostart,...,\radioend} {%
    \gappto\radiocontent{=}%
    \expandafter\gappto\expandafter\radiocontent\expandafter{\i}%
    \ifnum\i<\radioend \gappto\radiocontent{,}\fi%
   }%
 \let\savedLayoutChoiceField\LayoutChoiceField%
 \let\LayoutChoiceField\MakeScaleField%
 \let\savedDefaultOptionsofRadio\DefaultOptionsofRadio%
 \renewcommand{\DefaultOptionsofRadio}{print,notoggletooff,borderwidth=1pt,bordercolor=white,width=\radiosize,height=\radiosize,bordersep=0pt}%
 \ChoiceMenu[ name=#1, radio, radiosymbol=6 ]{}{\radiocontent}%
 \let\DefaultOptionsofRadio\savedDefaultOptionsofRadio%
 \let\LayoutChoiceField\savedLayoutChoiceField%
}
\begin{document}
\begin{Form}
 This is a scale from 1 to 6 :
 \formscale{Question}{1}{6}

 \ChoiceMenu[ name=q2, radio ]{}{1,2,3}
\end{Form}
\end{document}

在此处输入图片描述

相关内容