2

I would like to simplify the way to type indicator functions. So I used package bbm and defined \newcommand{\1}{\mathbbm{1}}

But I actually want something like \mathbbm{1}_{XXX}=\newcommand{1}{XXX}. So that after I typed \1 and I can continue to type {XXX} and the what comes up is \mathbbm{1}_{XXX}.

  • @I don't know how to edit this... Please help me. thanks! – Mathemagician Nov 14 '15 at 16:52
  • 1
    Do you mean \1{X} to become \mathbbm{1}_{X}? – egreg Nov 14 '15 at 16:52
  • @egreg X means the stuff that I want to type in. For example, I want \1{x_1=x_2} defined to be \mathbbm{1}_{x_1=x_2} – Mathemagician Nov 14 '15 at 16:53
  • Just use \newcommand\1{\mathbbm{1}_} – Mark Nov 14 '15 at 19:15
  • Simplest would be to type \1_{x_1=x_2}. One extra character, but it is clearer in the source what is intended. – James K Nov 14 '15 at 22:36
8

Just define \1 with an argument:

\newcommand{\1}[1]{\mathbbm{1}_{#1}}

Full example

\documentclass{article}

\usepackage{bbm}

\newcommand{\1}[1]{\mathbbm{1}_{#1}}

\begin{document}

$\1{x_1=x_2}$

\end{document}

enter image description here

On the other hand, the package bbm only provides bitmap fonts; you can get a scalable Type1 font from bbold.

\documentclass{article}
\usepackage{amsmath}

\DeclareRobustCommand{\1}[1]{\text{\usefont{U}{bbold}{m}{n}1}_{#1}}

\begin{document}

$\1{x_1=x_2}$

\end{document}

enter image description here

I wouldn't recommend \usepackage{bbold}, because it clobbers the \mathbb font from amssymb (or amsfonts).


Let's stick to \newcommand. When you do it, you can specify a number of arguments:

\newcommand{\foo}[2]{...}

would mean \foo should be followed by two braced groups, the arguments, like

\foo{Abc}{def}

and, in the definition text, you refer to the first braced group with #1 and to the second one by #2. In our case

\newcommand{\1}[1]{\mathbbm{1}_{#1}}

we just have one argument. This tells TeX that, when it finds \1{X}, it has to replace it with

\mathbbm{1}_{X}

The second version, with \DeclareRobustCommand is the same; this has the feature that, when the command \1 is found in a section title, it's written out as such in the auxiliary file. Just a technical thing, nothing to really worry about; using \newcommand in the second solution would be as good.

  • Where can I find the instructions on how to use \newcommand. I am not able to find it online. – Mathemagician Nov 14 '15 at 16:54
  • 2
    @DaqianSun - Any introduction to LaTeX explains how \newcommand is to be used. See, e.g., section 6.1.1. of the Not so short introduction to LaTeX2e. – Mico Nov 14 '15 at 16:58
  • @DaqianSun See Chapter 8 in dickimaw-books.com/latex/novices/index.html – egreg Nov 14 '15 at 17:04
  • @DaqianSun I added some basic theory about \newcommand. – egreg Nov 14 '15 at 17:16
  • 1
    @cfr It adds a layer to an already hard topic for beginners. – egreg Nov 15 '15 at 10:16

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.