18
\DTLforeach takes three compulsory arguments, not two as in your example. This fixes your example:
\documentclass{memoir}
\usepackage{datatool}
\DTLsetseparator{|}
\DTLloaddb{players}{database.csv}
\begin{document}
\DTLforeach*
{players}% database label
{\name=name,\points=points}% assignment
{% Stuff to do at each iteration:
\subsection{\name}
\...
answered May 31 '14 at 20:49
Nicola Talbot
37.6k22 gold badges7373 silver badges119119 bronze badges
15
My datatool skills are limited, so the following solution uses TeX primitives and PGFs mathematical engine and also its \pgfutil@in@ macro/conditional.
Interaction
Line 99: Minimum ratio a Cardinal needs to get elected as Pope.
\pgfmathparse{2/3*\the\value{sumVotes}}
Line 70: Number of Cardinals that will be marked if no one has reached the limit. As ...
answered Mar 10 '13 at 18:05
Qrrbrbirlbel
83.7k66 gold badges203203 silver badges349349 bronze badges
13
Here's a possible implementation; the delimiters can be changed.
\documentclass{article}
\usepackage{amsmath,multicol}
\usepackage{xparse}
\ExplSyntaxOn
\NewDocumentCommand{\constraints}{omO{x}}
{
\IfValueTF{#1}{\begin{multicols}{#1}\centering}{\begin{center}}
\egreg_costraints:nn { #2 } { #3 }
\IfValueTF{#1}{\end{multicols}}{\end{center}}
}
\...
answered Nov 25 '19 at 10:55
egreg
889k110110 gold badges22732273 silver badges37163716 bronze badges
12
The example below defines some commands that allow you to add entries to multiple databases. You can then use the example command \xgls instead of \gls and it will index the entries for each of the databases. So if pdf is in the glossary, acronym and index database, \xgls{pdf} will add a location to each database, whereas if html is only in the acronym and ...
answered Jun 10 '13 at 20:46
Nicola Talbot
37.6k22 gold badges7373 silver badges119119 bronze badges
12
Quick and dirty expl3 implementation:
First you load the CSV file with \LoadCSV{<label>}{<file>}. This command will open the file and load the contents of the CSV into <label>. The contents of the file are read verbatim (all catcodes are other (12), except for spaces (10)).
Then you get a field with \GetCSV{<label>}{<line>}{&...
answered Feb 11 '19 at 20:11
Phelype Oleinik
56.5k1818 gold badges108108 silver badges184184 bronze badges
12
You can automate the job by exporting the Excel spreadsheet to a comma delimited file (for example subscripts.csv) and reading your data with the readarray package.
MWE
Assuming that the content of subscripts.csv is:
1,2
1,3
2,39
7,5
26,5
The following code:
\documentclass{article}
\usepackage{readarray}
\usepackage{forloop}
\newcommand\constraint[2]{$x_{#...
12
Use Excel's CONCAT function.
It's probably easiest to do this in Excel, especially if it's a one-time thing. Excel has several text-manipulation functions, and I have often found it a very convenient way to generate several similar lines of text or code. CONCAT(text1,text2,...) concatenates a bunch of text and data values into one text output.
If columns ...
10
TeX's registers can be addressed either by name or by number. To keep a track of the numbers allocated to names, it is necessary to have an allocation routine, which \newcount provides an interface for. Thus when you do
\newcount\foo
you define \foo to mean \count<number>, and mark <number> as 'taken'. If you subsequently do
\let\foo\...
answered Jan 9 '13 at 19:00
10
The datatool package uses an insertion sort algorithm. The gory details, for anyone who's interested, are described in section 4.10 of the datatool documented code. However, I agree with the comments. TeX is a typesetting tool (and a very good one) but there are a lot of things that it's not, which is why datatool has an accompanying helper application ...
10
With readarray (and listofitems included).
First, I employ readarray macros
\readarraysepchar{\\}
\readdef{personalinfo.csv}\myrawdata
to take the contents of personalinfo.csv and place it into the macro \myrawdata, all the while converting end-of-record tokens into \\. Then, with listofitems macros,
\setsepchar{\\/,}
\readlist*{\mydata}{\myrawdata}
I ...
answered Feb 12 '19 at 0:35
Steven B. Segletes
198k1010 gold badges266266 silver badges513513 bronze badges
9
Joseph has explained the reason why the problem arises. Here's a possible workaround. I define a set of macros that set up two pools of token registers and count registers, from which to choose new ones when \DTLdbnewdb is called and that are reinserted in the pool when \DTLdeletedb is issued.
One can increase the size of the pool, with the following macros ...
answered Jan 10 '13 at 11:43
egreg
889k110110 gold badges22732273 silver badges37163716 bronze badges
9
\documentclass{article}
\usepackage{array}
\usepackage{longtable}
\makeatletter
\let\oldref\ref
\def\ref#1{\immediate\write\@auxout{\string\expandafter\gdef\noexpand\csname REF:#1\string\endcsname{}}%
\oldref{#1}}
\def\zz#1#2{\noalign{%
\expandafter\ifx\csname REF:#1\endcsname\@empty
\def\@currentlabel{#2}\label{#1}%
\else
\aftergroup\zzapline
\fi}#2}
\...
answered Jan 13 '14 at 18:00
David Carlisle
595k5151 gold badges13471347 silver badges21382138 bronze badges
9
You can set locally the catcode of & when reading the data. It will not disturb the use of & later, and unlike \detokenize it will not break other commands like non-ascii input in your input:
\documentclass[10pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[a4paper]{geometry}
\catcode`\&=12
\...
answered Jun 10 '16 at 7:23
Ulrike Fischer
265k1616 gold badges394394 silver badges841841 bronze badges
9
Let us say we have the following code:
\documentclass[11pt,a4paper,sans]{moderncv}
% moderncv themes
\moderncvstyle{classic} % casual, classic, banking, oldstyle and fancy
\moderncvcolor{blue}
\usepackage[utf8]{inputenc}
\usepackage[scale=0.75]{geometry}
% personal data
\name{John}{Doe}
\title{Resumé title}
\address{street and number}{postcode city}{...
8
datatool already loads fp which provides \FPround{<out>}{<in>}{<num>}, rounding <in> to <num> decimal places and stores it in <out>. datatool mirrors this with \DTLround (and/or \DTLtrunc if you wish to truncate rather than round):
\documentclass{article}
\usepackage{datatool,filecontents}% http://ctan.org/pkg/{datatool,...
answered Jul 9 '13 at 1:52
Werner
524k106106 gold badges12241224 silver badges20162016 bronze badges
8
I've just uploaded v2.13 to CTAN. It will probably take a day or so to propagate through the mirrors and distros, but once it's available you can use the code below. The best solution is to only define the database once (before the loop) and clear it each time round the loop. This means that you're not constantly allocating new registers. The new version ...
answered Jan 15 '13 at 15:31
Nicola Talbot
37.6k22 gold badges7373 silver badges119119 bronze badges
8
When using the babel package with the french option, semicolons (and colons, exclamation marks and question marks) are made active so the spacing around these punctuation symbols can be corrected for the French style of putting space before and after the symbol:
"Normal" spacing:
French spacing:
If you use the semicolon as the field separator in your data ...
8
As Percusse pointed out, PGFPlots first collects all TikZ commands (like \draw) and then executes them at the very end of the axis environment, which leads to the last circle being drawn three times: during every loop iteration, another \draw (axis cs:\x,\y)... is added to the list of commands, and at the very end, when \x and \y contain -3 and -4, ...
8
It seems that \ce requires its argument to be expanded (presumably because \ce parses it) so you need to use \expandafter to ensure the argument is in the correct format:
\expandafter\ce\expandafter{\methane}
Explanation
Inside \ce, active characters (like ^, _ and {) have a different meaning. An intuitive meaning, but technically very different from ...
answered Jan 26 '17 at 15:25
Nicola Talbot
37.6k22 gold badges7373 silver badges119119 bronze badges
8
A variant using datatool and some counters.
\documentclass[11pt]{report}
\usepackage{filecontents}
% this just saves the data to a text file
\begin{filecontents*}{deathdata.txt}
Sl.,Unique ID,Name,Gender,Death
1,DBC0001,Mr. John,M,Y
2,DBC0002,Miss Elizabeth,F,Y
3,DBC0003,Mr. Thomas,M,N
4,DBC0006,Miss Maya,F,N
5,DBC0005,Mr. Gilbert,M,N
6,DBC0004,Mr. Dinesh,M,...
answered May 11 '17 at 10:47
Torbjørn T.
185k1515 gold badges331331 silver badges514514 bronze badges
8
The last \\\hline shouldn't be inside the the loop but after it, so that the code of the loop doesn't triggers the creation of a new row:
\documentclass{article}
\usepackage{datatool}
\usepackage{booktabs}
\usepackage{longtable}
\DTLnewdb{docreview}
\newcommand{\review}[6]{%
\DTLnewrow{docreview}%
\DTLnewdbentry{docreview}{Date}{#1}%
\DTLnewdbentry{...
answered Apr 24 '19 at 10:15
Ulrike Fischer
265k1616 gold badges394394 silver badges841841 bronze badges
7
\csname is a useful construct for defining a "dynamic" macro name based on some input, but when you're using the same basic structure in different places, you have to make sure the constructed macro names really match up.
For instance, comparing this
\expandafter\gdef\csname\Dir Color\endcsname{\ExpandedDirColor}%
with that
\xdef\DirBColor{\csname../...
7
According to the datapie documentation (section 7.3 Pie Chart Colours, p 131):
The datapie package predefines colours for the first eight segments
of the pie chart. If you require more than eight segments or if you
want to change the default colours, you will need to use
\DTLsetpiesegmentcolor{<n>}{<color>}
The first argument <n&...
answered Jul 8 '13 at 5:32
Werner
524k106106 gold badges12241224 silver badges20162016 bronze badges
7
Both simple problems. The misplacement of 'Albert' is as mentioned in a comment due to a missing %:
\DTLiffirstrow{}{\tabularnewline}%
The odd business with the q is caused by having & \tabularnewline at the end of the header row, which mis-places things. Try instead just \\:
\documentclass{article}
\usepackage{datatool}
\usepackage{siunitx}
\...
answered Jul 12 '13 at 8:16
7
Deferred writing and package atenddvi
Package atenddvi provides the hook \AtEndDvi to get stuff written at the shipout of the last page. Two LaTeX runs are needed at least for knowing, which is the last page. Despite the name the output type DVI, PDF or whatever does not matter.
Immediate writing and package atveryend
If your data does not contain data ...
answered Oct 13 '13 at 21:47
Heiko Oberdiek
250k2020 gold badges633633 silver badges993993 bronze badges
7
Here's a possible solution:
\documentclass{article}
\usepackage{eso-pic}
\usepackage{fancyhdr}
\usepackage{blindtext} % just for the example
\usepackage[headsep=3cm,top=5cm]{geometry}
\usepackage{datatool}
% create sample csv file
\begin{filecontents*}{test.csv}
Id,myauthor,mydate,myaddress
1,Sebastian,12.12.2012,XYZ road,XYZ city
2,Rose,12.12.2013,XYZ ...
answered Dec 16 '13 at 13:12
Nicola Talbot
37.6k22 gold badges7373 silver badges119119 bronze badges
7
You can first of all use a macro to hold the name of the .csv file in abc.tex:
\documentclass{article}
\usepackage{datatool}
\begin{document}
...
\DTLloaddb[noheader,keys={Temperature,Time,T2G}]{data}{\csvname.csv}
...
\end{document}
Then you can call xelatex from the command line by saying
xelatex -jobname=abc-pqr '\def\csvname{pqr}\input{abc}'
...
answered Dec 21 '13 at 18:35
egreg
889k110110 gold badges22732273 silver badges37163716 bronze badges
7
As I hinted in a comment, even if Sharelatex allows to use lualatex as compiler for your documents, it does not allow network connections from luatex code. I performed the following test:
Wrote the following testing file, which attempts a connection to Google Geocoding API to get a JSON containing geocoding information about the location "1600 Amphitheatre ...
7
You are ending every row with \\ inside the \DTLforeach. This means that you are executing code after the final \\ and such code can easily lead to an empty row at the end of the tabular. You can visualize the problem by using a preamble like {>{blub}c}. I suggest moving the \\ to the beginning, and suppressing the first \\ with \DTLiffirstrow:
\...
answered Apr 4 '16 at 7:31
Ulrike Fischer
265k1616 gold badges394394 silver badges841841 bronze badges
Only top voted, non community-wiki answers of a minimum length are eligible
Related Tags
datatool × 317tables × 49
csv × 35
database × 24
macros × 18
tikz-pgf × 11
longtable × 11
csvsimple × 9
glossaries × 8
conditionals × 8
pgfplotstable × 8
expansion × 8
sorting × 8
pgfplots × 7
siunitx × 7
spacing × 5
xetex × 5
errors × 5
indexing × 5
loops × 5
hyperref × 4
external-files × 4
automation × 4
etoolbox × 4
xstring × 4