I'm wondering how to define a LaTeX command \x
that prints "def1" when I write \x{name1}
, reading from an external (dictionary) file having a structure like
{name1}{def1}
{name2}{def2}
etc.
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityI'm wondering how to define a LaTeX command \x
that prints "def1" when I write \x{name1}
, reading from an external (dictionary) file having a structure like
{name1}{def1}
{name2}{def2}
etc.
If the external file dict.dat
is organized as
\entry{name1}{def1}
\entry{name2}{def2}
then
\newcommand{\entry}[2]{%
\expandafter\newcommand\csname entry@#1\endcsname{#2}}
\newcommand{\x}[1]{\csname entry@#1\endcsname}
\input{dict.dat}
will do what you're looking for.
\expandafter\ifx\csname entry@#1\endcsname\relax\ERROR\else\csname entry@#1\endcsname\fi
would be nice.
– Bruno Le Floch
Oct 19 '11 at 7:21
\x{name2}
, right? If so, please correct. I would have but just wanted to make sure. Also, is modifying the external file an option? – Peter Grill Oct 18 '11 at 23:24