2

I wrote the following commands for dynamic variable names and assignment

% in class file
\RequirePackage[ngerman]{babel}
\RequirePackage[T1]{fontenc}
\RequirePackage[utf8]{inputenc}

% in latex file
\newcommand{\rev}[2]{%
  \expandafter\def\csname rev_\revprefix#1\endcsname{#2}
}

\newcommand{\grev}[1]{%
  \ifcsname rev_\revprefix#1\endcsname%
  \csname rev_\revprefix#1\endcsname
\fi}

This works for well for ASCII characters, e.g.

\rev{value1}{Test}
\grev{value1} % gives Test

but not for Umlauts (only in \rev)

\rev{value2}{Groß}
\grev{value2} % gives GroT1ss

I know, it has something to do with the internal character representation and expansion but I could not find out how to fix this. Any ideas?

Update [2014-01-15]

It is

\newcommand{\revprefix}{}

The problem only occurs in a TextField of hyperref:

\TextField[name=test, value=\grev{value2}]{test}
  • I don't get anything strange; \grev{value2} prints “Groß” as expected. What's \revprefix? – egreg Jan 15 '14 at 8:49
  • It's empty: \newcommand{\revprefix}{}. But you are right! This problem only occurs in a Textfield. I will update the problem description. – Thorsten Jan 15 '14 at 9:12
  • 1
    It has nothing to do with \grev: also \TextField[name=test, value=Groß]{test} shows the same problem. – egreg Jan 15 '14 at 9:18
  • Right. So, the problem is the wrong encoding!? – Thorsten Jan 15 '14 at 9:30
  • When I define a temporary macro by \defpdfstring{\tmpval}{\grev{value2}} und use \tmpval in \TextField then it works. – Thorsten Jan 15 '14 at 10:38
1

You need a different way to produce the string, with \defpdfstring

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}

\usepackage{hyperref}

\newcommand{\revprefix}{}

\newcommand{\rev}[2]{%
  \expandafter\def\csname rev_\revprefix#1\endcsname{#2}%
  \expandafter\pdfstringdef\csname tfrev_\revprefix#1\endcsname{#2}%
}

\newcommand{\grev}[1]{%
  \ifcsname rev_\revprefix#1\endcsname
    \csname rev_\revprefix#1\endcsname
  \fi}
\newcommand{\tfgrev}[1]{%
  \ifcsname rev_\revprefix#1\endcsname
    \csname tfrev_\revprefix#1\endcsname
  \fi}

\begin{document}

\rev{value1}{Test}
\grev{value1} % gives Test

\rev{value2}{Groß}
\grev{value2}

\TextField[name=test, value=\tfgrev{value2}]{test}

\end{document}

Of course, if you don't need \grev other than in text forms, defining \grev is useless.

| improve this answer | |

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.