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.
\docuentclass[pdftex,a4paper,12pt,oneside]{book}%

\begin{document}

\newcommand{\tmpa}{}
\newcommand{\tmpb}{}
\newcommand{\tmpc}{}

\renewcommand{\tmpc}{tmpc1}  
\renewcommand{\tmpa}{\tmpc}
\renewcommand{\tmpb}{\tmpc}
\noindent tmpa: \tmpa \\
tmpb: \tmpb \\
tmpc: \tmpc \\
\renewcommand{\tmpc}{tmpc2}
tmpa: \tmpa \\
tmpb: \tmpb \\
tmpc: \tmpc 

\end{document}

Result:

tmpa: tmpc1

tmpb: tmpc1

tmpc: tmpc1


tmpa: tmpc2

tmpb: tmpc2

tmpc: tmpc2

Changing the value of tmpc changes the values of the other two variables. How can I assign only the value of tmpc without this pointer like effect?

share|improve this question
    
Replace \renewcommand{\tmpa}{\tmpc} \renewcommand{\tmpb}{\tmpc} by \let\tmpa\tmpc \let\tmpb\tmpc. And take a look at "TeX by Topic" (texdoc texbytopic) –  Axel Sommerfeldt Apr 16 '12 at 6:59
    
It is difficult to understand why you use \tmpc in \tmpa and \tmpb if you do not want this `pointer effect'. Just define another command ?! You should provide more context so that one can think of a workaround. Right now, your problem appears rather unclear to me. –  Alfred M. Apr 16 '12 at 7:03
add comment

1 Answer

up vote 7 down vote accepted

When TeX finds a macro it expands it to its current meaning; so with

\newcommand{\tmpa}{}
\newcommand{\tmpb}{}
\newcommand{\tmpc}{}

\renewcommand{\tmpc}{tmpc1}  
\renewcommand{\tmpa}{\tmpc}
\renewcommand{\tmpb}{\tmpc}

when \tmpa is found, it's replaced first by \tmpc and then by tmpc1 (which is what \tmpc is defined to expand to).

If you want to freeze the meaning, then \let is the instruction to use:

\let\tmpa\tmpx

will assign to \tmpa the current meaning of \tmpx and subsequent changes to the latter command will not influence the meaning of \tmpa.

There's no "LaTeX interface" to \let, because such commands are intended to be used by "programmers" rather than "users".

share|improve this answer
add comment

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.