3

I want to define \newcommand{\B} in 2 different ways and switch between them in the simplest way – just using a comment mark, %. Let's look at the example:

\documentclass[a4paper,9pt]{article}
\usepackage[utf8]{inputenc}

% My 1st definition 
\newcommand{\B}[1]{\textbf{#1}}
% My 2nd definition (it’s wrong that’s way I’m asing)
\newcommand{\B}{$\ldots$}

\begin{document}
Let \B{1.345} be 

\end{document}

Using first definition the value 1.345 is bolded. If I use second definition I should always get only $\ldots$ so value 1.345 should be removed. I tried to add spaces (crude solution) but value skipped line below. Any suggestion?

2
  • 2
    Note that the article class doesn't support the 9pt fontsize option without loading, e.g, the extsizes package.
    – lockstep
    Apr 7, 2013 at 11:14
  • 3
    If you use \renewcommand for the second definition, you only have to add/remove one comment mark instead of adding one and removing one Apr 7, 2013 at 15:47

1 Answer 1

7

You need to “gobble” the argument {1.345} in the \ldots case. (Specify \B with one argument but do not use #1.)

Reference for “gobbling”

Code

\documentclass[a4paper,9pt]{article}
\usepackage[utf8]{inputenc}

% My 1st definition 
% \newcommand{\B}[1]{\textbf{#1}}
% My 2nd definition
\newcommand{\B}[1]{$\ldots$}% (do’nt use #1 here but specify [1])

\begin{document}
Let \B{1.345} be 

\end{document}

Output

Let … be

3
  • but how, with this approach, will it ever be possible to get the output "1.345", which is apparently wanted sometimes? wouldn't an optional argument, with default of \ldots, be more appropriate? Apr 7, 2013 at 12:22
  • @barbarabeeton If I understand Op correctly, he wants a document-wide switch so he he swaps the definition of \B in the preamble. One could also introduce a starred version that forces one of both settings. Apr 7, 2013 at 13:22
  • You understood correctly and using a conditional (if statement) would be more elegant. But it works fine for me. Thank you. My primary purpose I described in a post: tex.stackexchange.com/questions/107245/…
    – Robert
    Apr 7, 2013 at 18:08

You must log in to answer this question.

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