1

MWE:

\documentclass{article}
\usepackage{clefval}
\begin{document}
\TheKey{test}{zez}
\def\mymacro{\TheValue{test}}
\makeatletter
\ifdefined\V@test \mymacro \else empty \fi
\ifdefined\mymacro \mymacro \else empty \fi
\end{document}

On first pass, when there is no .aux file yet, trying to use \mymacro leads to the weird error:

! Package inputenc Error: Invalid UTF-8 byte "A0.

The implementation of clefval builds up the resulting macro name with \csname, without a guarantee that it exists. As MWE demonstrates, I can check if that name is defined, but in general case I need to check it via \mymacro, which does not work that way. Trying to expand it before checking leads to the same error.

  • \csname mymacro\endcsname just becomes \relax if \mymacro wasn't defined (it also makes \mymacro become \relax from that point on). – Henri Menke Jan 21 at 8:18
  • Well the issue is that clefval uses ^^a0 as the place-holder for undefined material, but buried away inside an internal macro. I'd be tempted to patch/change that internal macro, if you are determined to use the package. Is that an option? – Joseph Wright Jan 21 at 8:19
  • @JosephWright well, the package is pretty simple, so if it is that troublesome, I would prefer to make a custom solution instead. I don't even need it's 2-pass functionality, as all keys are defined at preamble stage, so a set of macros with the same prefix should be enough. – bodqhrohro Jan 21 at 8:34
1

For strange reasons, clefval uses a strange byte in its code.

If you just need a set of macros for storing values and such storing is done in the preamble, you can do as follows.

\documentclass{article}

\makeatletter
\newcommand{\defkey}[2]{%
  \global\@namedef{bodqhrohro@#1}{#2}%
}
\newcommand{\getkey}[1]{%
  \ifcsname bodqhrohro@#1\endcsname
    \@nameuse{bodqhrohro@#1}%
  \else
    ??????
  \fi
}
\newcommand{\keyexistTF}[1]{%
  \ifcsname bodqhrohro@#1\endcsname
    \expandafter\@firstoftwo
  \else
    \expandafter\@secondoftwo
  \fi
}
\makeatother

\defkey{Test}{test}
\defkey{X}{x}

\begin{document}

Test: \getkey{Test}

X: \getkey{X}

Y: \getkey{Y}

\keyexistTF{X}{Hurray!}{Boooh!}

\keyexistTF{Y}{Hurray!}{Boooh!}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.