Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I find that I much prefer \varphi to \phi and generally would rather use the \varphi than the \phi. But it's three more characters to type \varphi instead of \phi, which is most troublesome. So I would like to swap the two commands. I tried a couple of things on my own, but one resulted in an infinite loop in compilation and the other led to \varphi taking over all of the \phi commands I made. What would be the correct way to do this?

share|improve this question
2  
\let\phi\varphi –  Gonzalo Medina Apr 1 '12 at 18:26
    
@Gonzalo This defines '\phi' to be '\varphi', but doesn't define '\varphi' to be the "old" '\phi'. –  JSchlather Apr 1 '12 at 18:38
5  
The idea is the same: \let\oldphi\phi \let\phi\varphi \let\varphi\oldphi –  Gonzalo Medina Apr 1 '12 at 18:42
1  
I usually say to go with \let\phi\varphi, as the two symbols very rarely are used together in the same document (a polite way to say: "never use both in the same document"). –  egreg Apr 1 '12 at 20:49
4  
@egreg: Never say never. An obvious example of using both in the same document is a document explaining the difference between \phi and \varphi. –  celtschk Apr 2 '12 at 9:01

3 Answers 3

up vote 23 down vote accepted

Try the following:

$\phi\varphi$
\let\temp\phi
\let\phi\varphi
\let\varphi\temp
$\phi\varphi$
share|improve this answer
1  
Okay, so my issue before is that I was using \renewcommand instead of \let. Could you elaborate on the differences between the two commands? –  JSchlather Apr 1 '12 at 18:49
7  
\let\a\b makes \a have the definition that \b has so \let\a\a is a no-op \newcommand\a{\b} makes a expand to \b so \newcommand\a{\a} makes a expand to itself and loop forever –  David Carlisle Apr 1 '12 at 18:57
3  
@DavidCarlisle Okay so it's essentially hard linking versus symbolic linking. Which is what I suspected the issue was. Thanks. –  JSchlather Apr 1 '12 at 19:04

For non-complex macros, using an interim macro to swap definitions is sufficient. However, if the macros (say, funcA and funcB) takes optional arguments, you need to use a different approach via letltxmacro's macro \LetLtxMacro{<new macro>}{<old macro>}:

\usepackage{letltxmacro}% http://ctan.org/pkg/letltxmacro
%...
\LetLtxMacro{\temp}{\funcA}
\LetLtxMacro{\funcA}{\funcB}
\LetLtxMacro{\funcB}{\temp}
share|improve this answer
1  
+1 for giving an answer with less \expandafters but more use than mine. –  David Carlisle Apr 1 '12 at 20:36

The usual way to exchange two values is to use a temporary command name to store one of them while swapping, but if, for no particular reason, you want to avoid the extra command name then:

\documentclass{article}

\begin{document}

$\phi\varphi$


\expandafter\mathchardef\expandafter\varphi\number\expandafter\phi\expandafter\relax
\expandafter\mathchardef\expandafter\phi\number\varphi

$\phi\varphi$


\end{document}
share|improve this answer
    
haha, saving up just that extra bit of namespace! –  romeovs Apr 1 '12 at 19:04
12  
What the…?! Cool! :-D –  morbusg Apr 1 '12 at 19:09
    
I see, you are using the input stream as temporary storage. –  Ryan Reich Jun 26 '12 at 23:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.