General ⇒ Latex as a programming language
Re: Latex as a programming language
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.)
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
Latex as a programming language
Latex as a programming language
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.lalop wrote:...Still missing the switch *hint hint* <3
Latex as a programming language
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''.
- Attachments
-
- lookupname.sty
- (5.6 KiB) Downloaded 217 times
Latex as a programming language
You can download the book for free. Follow the link that appears in the page I linked to in my previous reply.lalop wrote:...I'll try to find that in the library...