I would like put picture into table, and my idea is define new command as below>

  • \newcommand{\EJ471}{\includegraphics[scale=0.150]{EJ_471.jpg}}

But compiler reports an error. If I use the command name for example \EJa, everything is all right. I've read similar questions as

But still I don't understand why it does not work.

  • 5
    What don't you understand? In my opinion the FAQ is really clear: tex.ac.uk/cgi-bin/texfaq2html?label=linmacnames Aug 10, 2012 at 15:28
  • @Jafan It's not normal here to include 'thanks' or similar: voting is the best way to indicate that something is helpful.
    – Joseph Wright
    Aug 10, 2012 at 16:53
  • NOTE: see the linked "similar question" for the solutions / workarounds. This question is for why it doesn't work.
    – user202729
    Apr 10 at 17:41

3 Answers 3


A long time ago in a galaxy far, far away....

someone wrote this:



By the rules of TeX syntax, the "name" of a macro that starts with a \ (backslash) character must either

  • consist of a single non-alphabetical character. Some examples: \, (insert thin space), \% ( the % character), \\ (insert line break), \[ (open display math), and \) (close inline math).


  • contain only uppercase and lowercase alphabetical characters: a-z and A-Z. No numerals, and no other characters belonging to non-letter categories either. (Well, there are certain ways of assigning "letter-category" status to non-letter characters, but that's a topic for a different discussion.)

Therefore, \EJ471 is not a valid macro name.

However, you could define a somewhat more general macro:


and use it as in \EJ{471} to pass EJ_471.jpg to the \includegraphics command. If you needed to process further jpg files that start with EJ_ (and end in .jpg, of course), you could simply keep invoking this macro with the appropriate arguments.

  • Well, there are certain ways of assigning "letter-category" status to non-letter characters, but that's a topic for a different discussion. -- I think this is the correct place ;-). The catcodes are the reasons for this. Aug 10, 2012 at 17:24
  • 1
    @MarcoDaniel - I have a feeling that the OP isn't all that interested in learning about catcodes just so that he/she can make \EJ471 into a valid TeX macro name after all. However, I may be wrong. :-) Please feel free to provide a separate, longer answer.
    – Mico
    Aug 10, 2012 at 17:40
  • 1
    @MarcoDaniel As Mico says, the question here seems to be focussed on one part of the story. Catcodes are 'advanced', and moreover we've already got questions about them.
    – Joseph Wright
    Aug 10, 2012 at 18:14

There are a variety of methods given here.

Combining some of them I've found this to be the best for a similar situation I was in.

\newcommand{\EJ}[1]{\csname EJ#1\endcsname}
\expandafter\newcommand\csname EJ471\endcsname{\includegraphics[scale=0.150]{EJ_471.jpg}}
\expandafter\newcommand\csname EJ8table\endcsname{\begin{tabular}{c|c} E & J \end{tabular}}


This is in the same spirit as Mico's answer, but a little more versatile.

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.