GeneralLatex as a programming language

LaTeX specific issues not fitting into one of the other forums of this category.
lalop
Posts: 63
Joined: Fri Sep 11, 2009 11:25 pm

Re: Latex as a programming language

Post by lalop »

AH! Thank you very much. I found out that it's not the package per se, but that it hates the guts out of \value{counter} (It pretty much puts in a tab everytime it's used in the same line, say Array(\value{row},\value{column}).) I just changed them all to \arabic{counter}, and it worked like a charm.

As a side note, are all counters global variables, or is it possible to define a counter only within a certain scope? (I already had that minor problem when trying to get \name[full]{person} to recursively call \name[first]{person} \name[last]{person}, although it helped that the row variable would necessarily be the same when it returned back.)

Recommended reading 2024:

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

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

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Latex as a programming language

Post by gmedina »

Counters defined with \newcounter are global.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Latex as a programming language

Post by gmedina »

lalop wrote:...Still missing the switch *hint hint* <3
Depending on your intent, you could use some of the TeX conditionals (perhaps an \ifcase command could be useful for you); Chapter 13 "Conditionals" in TeX by topic, by Victor Eijkhout, contains an excellent description of the various types of conditionals.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
lalop
Posts: 63
Joined: Fri Sep 11, 2009 11:25 pm

Latex as a programming language

Post by lalop »

Thanks again, I'll try to find that in the library.

I thought I would share what I made as thanks. It seems bug-free when checking on a fairly large old story that wrote with the old \name macro, and also in my additional testing. I would've preferred being able to preserve the old \cachedata when you call \name, but it doesn't seem possible.

In either case, it automatically outputs the "placeholdar" message if what you're looking for is empty, which already makes it less error-prone than the old macro.

Code: Select all

%	USAGE IN PREAMBLE:
%	Firstly, near the very top, \usepackage{lookupname} .
%
%	In the lower preamble of your main file, read out an array called Names.  This is a sample Names array:
%
%	\readarray{Names}{%
%		cargoship&Maurent&&&&&%
%		outercolony&Vinda&V&&&&%
%		aide&Marius&Robert&Jr&&&%
%		pirateship1&\emph{Rakoza}&&&&&%
%		headmaster&Albus&Dumbledore&Parzival&Wolfric&Brian&%
%	}%
%
%	The delimeter & has the effect of separating into columns.
%
%	By default, the first column is an identifier of a person, the other 5 are the person's names.  The first/last names are columns 2/3, respectively.
%
%	You can add more names per person by \setnamesperperson{number}, e.g. \setnamesperperson{20}  BUT NOTE that you'd also have to add more & per line.  The number of & needs to be equal to namesperperson+1.
%
%
%
%	IN ACTUAL DOCUMENT:
%	Use \name[number,first,last,full,or shortcut]{identifier}.  \name{identifier} or any unknown shortcut defaults to first name.  There are no shortcuts for names > 2.  One has to use \name[3]{Marius},...,\name[5]{Marius}.
%
%	e.g. \name[full]{headmaster} gives ``Albus Dumbledore'' with the above array.  A shortcut is \name[f]{headmaster} giving the same thing.
%
%	If you wanted to announce his whole name, it'd have to be:
%		\name{headmaster} \name[3]{headmaster} \name[4]{headmaster} \name[5]{headmaster} \name[las]{headmaster}
%	The idea is that this is pretty rare, and mostly when you want a full name it's usually just the first and last.
%
%
%	ERROR-CHECKING:
%	\name will automatically output the word ``placeholdar'' (with an a, to avoid legitimate placeholders) if you try to specify an out-of-bounds array element, if the name/person you specify does not exist, or if it does not recognize what you put in the [ ] box.  So search your file for the word ``placeholdar''.
Edit: It didn't seem appropriate to make it default to first name no matter what was in the [ ] box, now that there was so much error-checking otherwise. So i made it default to placeholdar if it doesn't recognize the [ ] word.
Attachments
lookupname.sty
(5.6 KiB) Downloaded 210 times
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Latex as a programming language

Post by gmedina »

lalop wrote:...I'll try to find that in the library...
You can download the book for free. Follow the link that appears in the page I linked to in my previous reply.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
lalop
Posts: 63
Joined: Fri Sep 11, 2009 11:25 pm

Re: Latex as a programming language

Post by lalop »

I missed that. Thanks.
Post Reply