# Possible to redefine \newfont?

I have read TeX Frequently Asked Questions -- What’s wrong with \newfont?, however, I'd still like to know the answer to this. In a style file I'm using there is:

\newfont{\myfont}{cmr17 scaled 2000}


... however, I'd like to "overload" / redefine this with a smaller scaling (1200) after the style file is loaded (still in the document preamble, though). I guess I'd like to use something like \renewfont{\myfont}{cmr17 scaled 2000} - but obviously, \renewfont doesn't exist :)

Since \newfont defines the command name cmd, which must not be currently defined, I guess the answer to the question is negative - but I better make sure and ask: is there a technique that would allow me to "overload" a font made by \newfont?

-

Well as the faq mentions \newfont is a really simple wrapper around the primitive \font. It actually simply adds a test if the font is already defined. So if you want to overwrite the definition simply use the primitive command:

\font\myfont=cmr17 scaled 1200 \relax


But my advice would be to avoid such hard coded font definitions. They make maintaining a style difficult and - as you see - making small changes awkward.

-
Many thanks, @Ulrike Fischer - good to know the 'TeX primitive' way too; cheers! –  sdaau Oct 7 '11 at 10:10

Thanks to Joon's Blog: How to undefine a command in LaTeX, I think I have it:

% undefine \myfont
\makeatletter
\let\myfont\@undefined
\makeatother

% ... then define it again:
\newfont{\myfont}{cmr17 scaled 1200}


Hope this helps someone,
Cheers!

-
No need for \makeatletter: \let\myfont\relax is sufficient. –  egreg Oct 6 '11 at 21:45
Many thanks for that @egreg - I'm never exactly sure when to "protect" with \makeatletter; good to know it's not needed here... Cheers! –  sdaau Oct 7 '11 at 7:06

This code will make \xnewfont have the same syntax as \newfont, but it will reject the definition of the control sequence only if it's not a font choosing command and, in that case, it will overwrite it.

However, Ulrike's suggestion should be followed: define fonts in term of higher level macros such as \usefont.

\makeatletter
\def\@newfont#1#2{\font#1=#2\relax}
\def\xnewfont#1{%
\ifdefined#1%
\def\next{\@iffont{#1}}%
\else
\def\next{\@newfont{#1}}%
\fi\next}
\def\@iffont#1{%
\edef\next{\meaning#1}\ch@ckiffont
\if@tempswa
\def\next{\message{*** Overwriting meaning of font \string#1*** ^^J}%
\@newfont{#1}}%
\else
\def\next{\@ifdefinable#1}%
\fi\next}
\def\ch@ckiffont{%
\edef\next{\next\detokenize{select font}\noexpand\@nil}%
\expandafter\ch@ck@ffont\next}
\begingroup
\edef\x{\endgroup
\def\noexpand\ch@ck@ffont##1\detokenize{select font}##2\noexpand\@nil}%
\x{\if\relax\detokenize{#1}\relax\@tempswatrue\else\@tempswafalse\fi}
\makeatother

-
Cheers @egreg - looks quite awesome, this code; definitely worth some closer study! –  sdaau Oct 7 '11 at 13:15