4

I am writing my own command and i would like to define for each letter :

\newcommand{\fletter}{\mathfrak{letter}}

but i can't do it for the letter i even with \renewcommand.

Is it possible to define that command for the letter i?

2
  • 3
    Hi and welcome, I am a lazy guy, others say efficient, as well. If you want to save typing time, get an editor which deals with stuff like that. Even tough LaTeX is made of/for macros, there are limits. Your editors will be greatful as well, if you avoid such shortcuts.
    – Johannes_B
    Apr 8, 2015 at 17:21
  • Perhaps using a capital "F" might improve your chances, but even there I am not sure. Apr 8, 2015 at 17:31

3 Answers 3

12

There are some cases where \renewcommand can be safely used; the main one is when we want to modify the behavior of a command we know about: the classical

\let\latexsection\section
\renewcommand{\section}{%
  ...<something to do before a section title>...
  \latexsection
}

is a frequently used trick.

Another case is something like

\renewcommand{\phi}{\varphi}

so we are sure that even if we type \phi the “open” shape will be used.

Other cases may include clobbering a command name which we know about and that we are absolutely sure we won't use in our document. Say that a package we load provides a command \foo that's only used at the top level and that we don't need; however, this is not really recommended.

A colleague once called me asking why he was not able to typeset the name of his coauthor in a paper, because LaTeX complained with weird error messages. The problem was that the coauthor was Turkish and his name contained Ş.

If one uses an encoding supporting Ş, what TeX sees is \c{S}, just as if this longer combination is typed. Well, it turned out that my colleague had

\renewcommand{\c}{\gamma}

in his preamble. (Actually it was \def\c{\gamma} which is even much worse, but the effect is the same.)

Never ever clobber accent commands like \c: you can't know whether they will be used for your bibliography, for instance.

Never ever use \renewcommand on a command which you don't precisely know about; be suspicious when \renewcommand appears in code obtained from not fully trusted sources.1. Ask some expert in case of doubt or if you start getting weird error messages from LaTeX.

NEVER EVER use \renewcommand on commands that are not listed in the index of the LaTeX manual or in the “Comprehensive List of LaTeX Symbols”, unless you know PRECISELY what you're doing.

Note that the command \fi is neither in index of the manual nor in the list of symbols.

Redefining commands such as \if, \fi, \box will make processing your document into a nightmare of mysterious errors, without getting any sensible output. It's similar to redefining \begin or \end, but much worse.

Experts can, in some cases, find a workaround to a tough problem by locally redefining a primitive so that it does a different job than it's normally expected to, but such tricks are very dangerous and can blow up very easily if not done in a controlled environment.

1I sometimes consider myself a trusted source. ;-)

1
  • 9
    You know egreg is being serious when there's a text in all caps, bold and italics. :) Apr 8, 2015 at 21:17
9

It's possible, in the sense you can make the definition if you use \renewcommand instead of \newcommand but it would break almost all latex usage, so I don't recommend it.

Even this fails

\documentclass{article}

\renewcommand{\fi}{\mathfrak{i}}


\begin{document}

\end{document}
6
  • Latex refuses to compile if is use \renewcommand instead of \newcommand.
    – gpst
    Apr 8, 2015 at 17:18
  • 2
    @Gomme Sure, because -- as David said -- you are breaking thousands of commands which use \fi as the end of a \if-clause. Apr 8, 2015 at 17:19
  • @Gomme I bet LaTeX is giving you a reason?
    – Johannes_B
    Apr 8, 2015 at 17:19
  • @Gomme No. latex never refuses. It makes the definition as specified, but then every command that makes any kind of test fails as you have redefined \fi which is tex's end-if command. Apr 8, 2015 at 17:20
  • 3
    it would break plain usage too. \fi is a primitive, and it's never a good idea to redefine one of those. Apr 8, 2015 at 17:34
4

Instead of clobbering \fi, which really would be a bad idea, define a command \f (which is available for being defined) as

\documentclass{article}
\usepackage{amsmath,amssymb}

\newcommand\f[1]{\mathfrak{#1}}
\begin{document}

$\f i$

\end{document}

Then you get your math frak as desired.

The nice thing about using \newcommand, as opposed to \def or just letting \let\f\mathfrak, is that \newcommand will warn you if the command name has already been taken. Of course you could also always do something like

\newcommand\f{}
\let\f\mathfrak

and then you get the warning before clobbering something that you may need for your document to compile as expected.

2
  • \let\f\mathfrak could even be more economical (if you are sure \f is not already defined)
    – Bordaigorl
    Apr 8, 2015 at 21:28
  • @Bordaigorl True.
    – A.Ellett
    Apr 8, 2015 at 21:29

You must log in to answer this question.

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