General ⇒ Latex as a programming language
Latex as a programming language
Hi, I wish to use either switch-case statements, and/or programming arrays (not the matrix stuff, but actual arrays of variables for storing and accessing data like a[5][2]).
Essentially, I'm trying to make a command like:
\name[last]{person}
which would output the person's last/first name which I define after the fact, and has to work for different people. A switch case statement:
Switch{name}
{
Case name1:
Case name2:
}
Would be very helpful. Array access might be less helpful (unless it has auto-hashing), but I could always define a simple hash algorithm, and I'd have some other uses for arrays anyway. (For example, spamming short answers to problems with ANS[counter].)
Right now, I implement \name by numerous annoying \ifthenelse statements (because, after all, that's the same thing as a switch), but it's very annoying to read even. I appreciate any hints.
Essentially, I'm trying to make a command like:
\name[last]{person}
which would output the person's last/first name which I define after the fact, and has to work for different people. A switch case statement:
Switch{name}
{
Case name1:
Case name2:
}
Would be very helpful. Array access might be less helpful (unless it has auto-hashing), but I could always define a simple hash algorithm, and I'd have some other uses for arrays anyway. (For example, spamming short answers to problems with ANS[counter].)
Right now, I implement \name by numerous annoying \ifthenelse statements (because, after all, that's the same thing as a switch), but it's very annoying to read even. I appreciate any hints.
NEW: TikZ book now 40% off at Amazon.com for a short time.

Re: Latex as a programming language
Well, can you please explain (to me, at least) what's your intention (from a typographical standpoint, of course) in requiring a typographical system to do such things?
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Re: Latex as a programming language
What is this? I simply am not good at making up characters' names on the spot, and wish to insert code which allows me to name them later. As for quickly typing in short answers to questions, it's just more convenient than to type out
Score: 78/90
Score: 66/100
...
Everytime. I'd like to be able to stick something like [78,90 ; 66, 100 , ... ] in an array and just do
\score
\score
...
Score: 78/90
Score: 66/100
...
Everytime. I'd like to be able to stick something like [78,90 ; 66, 100 , ... ] in an array and just do
\score
\score
...
Re: Latex as a programming language
Ah, now I see your intent. Right now (I must confess), I'm really, really exhausted but I'm sure that someone else will offer helpful advise.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
-
- Site Moderator
- Posts: 814
- Joined: Tue Jul 01, 2008 2:19 pm
Re: Latex as a programming language
I'd look in the first instance at the datatool package.
Joseph Wright
Re: Latex as a programming language
Very nice find! This would seem to allow for arrays, of a sort.
Latex as a programming language
Another option (for array data structures) could be the arrayjob package.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Re: Latex as a programming language
An even better find! (It's not nearly as roundabout.)
Still missing the switch *hint hint* <3
Still missing the switch *hint hint* <3
Latex as a programming language
Hi again,gmedina wrote:Another option (for array data structures) could be the arrayjob package.
arrayjob is almost passable. The only problem is that \checkarrayname seems to create a tab every time (and it's necessary, as it's the only way to actually access the array data to compare and stuff aside from actually printing it out).
For example, if an array is called Names, then
a\checkNames(2,3)b
gives out something like:
Code: Select all
a b
Latex as a programming language
I don't undestand your question. The followng simple example doesn't behave as you mention:
Code: Select all
\documentclass{article}
\usepackage{arrayjob}
\begin{document}
\newarray\Names
\readarray{Names}{Abel&Borel&Cantor&Dedekind&Eisenstein&Fermat&Galois&Hilbert}
\dataheight=4
a\checkNames(2,3)b
\cachedata
\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...