Math & Sciencea macro question

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
kent
Posts: 57
Joined: Thu Oct 20, 2016 3:41 pm

a macro question

Post by kent »

Define

Code: Select all

\pgfmathsetmacro{\lpx}{veclen(\xpx,\ypy)}
\pgfmathsetmacro{\lpxx}{veclen(\xpxx,\ypyy)}
where we assume that these definitions of the two above PGF macroes are OK.

If I then redefine as follows (ie. switching the content of \lpx and \lpxx)

Code: Select all

\def\tmptmptmptmp{\lpxx}
\def\lpxx{\lpx}
\def\lpx{\tmptmptmptmp}
it seems that the pdflatex execution halts without any error message.
Any comments on why are appreciated.
Kent
Last edited by cgnieder on Sat Apr 07, 2018 2:42 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

kaiserkarl13
Posts: 707
Joined: Tue Mar 25, 2008 5:02 pm

a macro question

Post by kaiserkarl13 »

Code: Select all

\def\tmptmptmptmp{\lpxx}
\def\lpxx{\lpx}
\def\lpx{\tmptmptmptmp}
The code above does this: (1) define a macro \tmptmptmptmp that expands to \lpxx; (2) define another one, \lpxx, that expands to \lpx; (3) define \lpx to expand to \tmptmptmptmp, which of course expands to \lpxx, which expands to\lpx, which expands to \tmptmptmptmp, which...I'm sensing an infinite loop here.

The command you probably want is \let, not \def. \let is a TeX primitive that takes the current definition of the second macro and copies that definition to the first. If the second later changes, the first is still the same.

Compare the output of these:

Code: Select all

\def\macroa{world!}
\def\macrob{\macroa}
\def\macroa{Hello }
% versus
\def\macroc{world!}
\let\macrod\macroc
\def\macroc{Hello }
\noindent
\macroa\macrob\\
\macroc\macrod
Post Reply