Graphics, Figures & TablesHow TikZ uses variable names.

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
topsquark
Posts: 71
Joined: Wed Oct 05, 2022 10:30 pm

How TikZ uses variable names.

Post by topsquark »

Okay, I have defined a number of variables by the notation c\s, where \s is a number in a foreach loop. When I refer to that later on, things like c0 and c1 seem to work just fine.

But I'm not naming a path L\s and the code seems to work, but when I tell TikZ to draw that path, it just returns a blank.

My guess is that \L1 is not what this path is called?

Thanks!

-Dan

Code: Select all

Code, edit and compile here:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\foreach \s in {0,...,1} {
\path[save path=\L\s] (0,0) -- (1,\s);
};
\draw[use path=\L1];
\end{tikzpicture}
\end{document}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
TikZ book
kaiserkarl13
Posts: 707
Joined: Tue Mar 25, 2008 5:02 pm

How TikZ uses variable names.

Post by kaiserkarl13 »

Welcome to the wonderful world of TeX macro expansion! The problem is on several levels. First, \L is already defined as a macro, so that may be confounding the problem. Second, \L1 is NOT a valid TeX macro: it is interpreted as \L 1. You CAN define a macro whose name is L1, but you would access it via \csname L1\endcsname. This leads us to another problem: from what I can tell, TikZ uses the command you enter as an argument to \let somewhere, which means \csname is being interpreted as the new name. I have tried a combination of \expandafter and \noexpand with no success, but I would strongly advise you to do this another way.

I may keep tinkering with this, but any solution I come up with will probably appear convoluted and/or "high-level" in nature.
Post Reply