TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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



share|improve this question
Welcome to TeX.SE. I assume you meant \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
up vote 9 down vote accepted

If the external file dict.dat is organized as



  \expandafter\newcommand\csname entry@#1\endcsname{#2}}
\newcommand{\x}[1]{\csname entry@#1\endcsname}

will do what you're looking for.

share|improve this answer
Exactly what I needed! A big thank you Peter, for your prompt answer and for your corrections! – bblue Oct 19 '11 at 7:18
Perhaps adding error checking, such as \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
@bblue: If this answers your question, you can check the ticker under the counter to accept it. – ℝaphink Oct 19 '11 at 9:18
@Raphink: Yes, sure! Thank you. – bblue Oct 19 '11 at 13:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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