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 keep on studying the use of nested tikzpicture environments (sorry) and I discover the next problem. I'm not sure but it sounds like a problem with "fragile" commands. Perhaps, the problem is the nested environments but I do not think so because the code works in many cases. It's very strange, that $\mathbf{\Pi}$ gives no problem while \textbf{textbf} is catastrophic !.

In the next code, I use the macro \place to put an object ( some tex's code) with the help of a node. I simplify a little bit the chain of macros but I keep the essential things.

Code I work with pgf 2.1 CVS

Uncomment the line

\documentclass{scrartcl}
\usepackage{amsmath,tikz}

\makeatletter
\def\place{\pgfutil@ifnextchar[{\place@i}{\place@i[]}}%
\def\place@i[#1]#2(#3)#{\place@ii[#1]{#2}(#3)}%
\def\place@ii[#1]#2(#3)#4{% 
\begin{tikzpicture}[overlay]
  \path (0,0)--(#3);
  \node[anchor=#1,rotate=#2] at (#3) {#4};
\end{tikzpicture}%
}% 

\begin{document}

Baseline%
\begin{tikzpicture}
 \draw[help lines] (0,-4) grid (5,1);
 \place[west]{0}(1,-2){$ \frac{2}{3}$} 
 \place[west]{-30}(2,-3){$\mathbf{\Pi}$} 
\end{tikzpicture}% 

% uncomment the next line with \place to see the problem
\begin{tikzpicture}
 %\place[west]{0}(4,0){\textbf{textbf}} 
\end{tikzpicture} 

% \noexpand resolves the problem 
\begin{tikzpicture}
 \place[west]{0}(2,0){\noexpand\textbf{textbf}} 
\end{tikzpicture}  

\end{document} 

Results

enter image description here

but if I don't use \noexpand:

enter image description here

What kind of problem I encountered?

share|improve this question
    
It works with the TeX Live version. –  egreg Mar 4 '12 at 18:57
    
@egreg do you have uncomment the line ? –  Alain Matthes Mar 4 '12 at 19:05
1  
@Altermundus: A small explanation is given here: tex.stackexchange.com/questions/18602/… You see that your solution doens't provide a bold output –  Marco Daniel Mar 4 '12 at 19:19
    
@MarcoDaniel yes the link is interesting, I need to test some ideas in this answer. How I can transform my code to avoid this problem? –  Alain Matthes Mar 4 '12 at 19:36
    
@Altermundus You're right. PGF doesn't like changing fonts, while math doesn't harm. I suggest you to use Martin's way of doing it. –  egreg Mar 4 '12 at 20:18
add comment

1 Answer

up vote 3 down vote accepted

Marco,thanks for the link to the answer of Martin and Martin thanks for the explanation using pgfinterruptpicture

The next code seems to remove the problem

\newbox\mybox   

\makeatletter
\def\place{\pgfutil@ifnextchar[{\place@i}{\place@i[]}}%
\def\place@i[#1]#2(#3)#{\place@ii[#1]{#2}(#3)}%
\def\place@ii[#1]#2(#3)#4{%
 %\setbox\mybox=\hbox{\pgfinterruptpicture #4\endpgfinterruptpicture}            
 \sbox\mybox{\pgfinterruptpicture#4\endpgfinterruptpicture}% from Martin Scharrer and egreg
\begin{tikzpicture}[overlay]
     \path (0,0)--(#3);
     \node[anchor=#1,rotate=#2] at (#3) {\box\mybox};
    \end{tikzpicture}%
}% 
share|improve this answer
2  
I'd use \sbox\mybox{\pgfinterruptpicture#4\endpgfinterruptpicture} which is color safe. –  egreg Mar 4 '12 at 21:19
    
@egreg Please, can you explain your comment ? The subtlety seems to be interesting ! I used Martin's code but I saw after your comment, the last line : \sbox\mybox{<content>} instead of`\setbox\mybox=\hbox{...` I don't understand why ! –  Alain Matthes Mar 4 '12 at 21:30
1  
\sbox\mybox{...} takes some supplementary precautions against possible color leaking that the primitive \setbox\mybox=\hbox{...} can't. –  egreg Mar 4 '12 at 21:39
1  
ok thanks. I need to find a link about this. It's amazing what you should know to make a correct code ! This site is incredible to find answer but sometimes it's difficult to find the good link. Fortunately some users have a good memory –  Alain Matthes Mar 4 '12 at 21:48
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.