Generalcsname

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
NinV
Posts: 69
Joined: Sun Oct 05, 2008 12:57 pm

csname

Post by NinV »

Hi,

I'm getting mad with LaTeX :)

Can you help me to understand why the following code doesn't work?

Code: Select all

  \n=13
  {\csname nv\romannumeral\n \endcsname}
   \setcounter{nv\romannumeral\n}{#1}
  % \the\value{nvxxxiv} % that shows the right value
........
   \ifnum \value{nvxiii}>0 {\seeds{\value{nvxiii}}{a}{5}}{}\fi % that cause an error message!
Did I misunderstand \csname?

Thanks,
Nino
Window + MiKTeX 2.7
Ubuntu + TexLive + Kile
Xandros (eeePC) + TeTex + TexMaker

Recommended reading 2024:

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

NEW: TikZ book now 40% off at Amazon.com for a short time.

phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

csname

Post by phi »

NinV wrote:Can you help me to understand why the following code doesn't work?
What do you mean with "doesn't work"? \n=13 either assigns 13 to the integer register \n (if it was allocated before) or prints the contents of the macro \n, followed by "=13", or gives an error message if \n is undefined. {\csname nv\romannumeral\n \endcsname} opens a group, prints the output of the macro named nv\romannumeral\n (after expansion) and closes the group again. If the command doesn't exist, it is defined as \relax and undefined immediately after. \setcounter{nv\romannumeral\n}{#1} must be inside a macro definition; it sets the LaTeX counter named "nv\romannumeral\n" to the contents of parameter #1. What is "\seeds"? Which error messages are shown? How are all the macros and counters defined? You have to support much more information and code.
NinV
Posts: 69
Joined: Sun Oct 05, 2008 12:57 pm

csname

Post by NinV »

Hi, Phi.
phi wrote:What do you mean with "doesn't work"?....
What is "\seeds"?
"\seeds" is a command which prints the output of nv\romannumeral\n, which in the code posted should be "nvxiii", after the expansion of nv\romannumeral\n.
Which error messages are shown? How are all the macros and counters defined?
You have to support much more information and code.
I didn't post all the code because I was sure that I didn't understand how \csname works. I've found another way to do the job, so I don't remember the error message :)
All the counters (ex. nvi...nvxxx, \n) are defined at the beginning of the sty file.
{\csname nv\romannumeral\n \endcsname} opens a group, prints the output of the macro named nv\romannumeral\n (after expansion) and closes the group again. If the command doesn't exist, it is defined as \relax and undefined immediately after.
By {\csname nv\romannumeral\n \endcsname} and \setcounter{nv\romannumeral\n}{#1} I meant to assign #1 to the already defined counter "nvxiii" (when "\n=13"). Was that right?
\setcounter{nv\romannumeral\n}{#1} must be inside a macro definition;
What do you mean? All the code I posted was inside a macro.

The problem is that I didn't understand if it is possible to use "arrays" of counters as I used to do in programming languages with variables (ex.: A[1]...A[n])!

Thank you very much for your attention and help.
Nino
Window + MiKTeX 2.7
Ubuntu + TexLive + Kile
Xandros (eeePC) + TeTex + TexMaker
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

csname

Post by phi »

NinV wrote:I didn't post all the code because I was sure that I didn't understand how \csname works.
\csname TOKENS \endcsname creates a control sequence out of whatever the TOKENS expand to. If you use LaTeX counters only, you don't need it at all, because it is used internally by the counter macros.
NinV wrote:
{\csname nv\romannumeral\n \endcsname} opens a group, prints the output of the macro named nv\romannumeral\n (after expansion) and closes the group again. If the command doesn't exist, it is defined as \relax and undefined immediately after.
By {\csname nv\romannumeral\n \endcsname} and \setcounter{nv\romannumeral\n}{#1} I meant to assign #1 to the already defined counter "nvxiii" (when "\n=13"). Was that right?
The \setcounter macro does the job, the \csname part has not any effect here. You would assign a counter which name is the expansion of something exactly like every other counter, i.e., without \csname.
NinV wrote:The problem is that I didn't understand if it is possible to use "arrays" of counters as I used to do in programming languages with variables (ex.: A[1]...A[n])!
It is possible, but not as easy as in other programming languages. TeX has no data structures except macros, token lists, and the control sequence hashtable. But if you use \setcounter, \value etc. with nv\romannumeral\n as counter name (like you did), then you can simulate integer arrays with that.
NinV
Posts: 69
Joined: Sun Oct 05, 2008 12:57 pm

Re: csname

Post by NinV »

Thank you very much. You has been very helpful!

Ciao,
Nino
Window + MiKTeX 2.7
Ubuntu + TexLive + Kile
Xandros (eeePC) + TeTex + TexMaker
Post Reply