When I use


I get the Missing \begin{document}. error and missing $ inserted if I move it inside the document.

How do I define a macro so that \F1 would expand to $\mathrm{F}_1$?

I can do


but then I have to use it as $\F1$ instead of just \F1.

  • 1
    As a general rule, macros can't have numbers in them. (Also, welcome to TeX.SX!) Commented Feb 20, 2014 at 18:09
  • @HeikoOberdiek: no, this is a different issue!
    – sds
    Commented Feb 20, 2014 at 18:12
  • 1
    Try defining it like \newcommand\F[1]{$\mathrm{F}_#1$}. That will define a small macro \F that looks at the next 'token' at puts it as the subscript. (Keep in mind that one-letter macros are generally bad to make) Commented Feb 20, 2014 at 18:13
  • @sds: Defining \H0, \H1, ... looks pretty close to \F1, doesn't it? Commented Feb 20, 2014 at 18:14
  • 1
    @sds Unfortunately, it's not a different issue. Use something similar to the command definition I posted above if you want this kind of functionality. (Reading the TeXbook or TeX by Topic would be good reading for you concerning this.) Commented Feb 20, 2014 at 18:15

1 Answer 1


Write \newcommand{\F}[1]{$\mathrm{F}_{#1}$}. This defines a macro which takes a single argument. You can then write \F1, which will expand to $\mathrm{F}_{1}$, \F2 which will expand to $\mathrm{F}_{2}$, etc. This form will work for any one letter argument, but you can also write \F{i,j} as short hand for $\mathrm{F}_{i,j}$.

  • 4
    Please, please, please use something more descriptive than \F in your actual document, though! Commented Feb 20, 2014 at 18:18
  • 1
    What can be more descriptive to the letter 'F' than the macro \F? ;-)
    – Yossi Gil
    Commented Feb 20, 2014 at 18:19
  • @SeanAllred: F1 is quite idiomatic.
    – sds
    Commented Feb 20, 2014 at 18:19
  • @sds seems like \newcommand*\Fscore{\mathrm{F}_1} would be a good definition (the macro doesn't describe the letter F but a mathematical function). Also since it is most likely to be used in math-mode the definition should not contain $. $\Fscore=\frac{...}{...}$
    – cgnieder
    Commented Feb 20, 2014 at 18:25
  • @srs That may be, but consider the shortcut I see all-too-often: \let\>\geq. One-letter (or excessively short) macro names are almost always used elsewhere. Redefine it and you risk breaking things in very bad, very unexpected ways. Commented Feb 20, 2014 at 19:49

Not the answer you're looking for? Browse other questions tagged .