A message from our CEO about the future of Stack Overflow and Stack Exchange. Read now.
23

Nothing much bad happens if you specify more columns than you use, so if you use {|*{50}{l|}} and no row has more than 3 entries latex doesn't use the extra col spec and just makes a 3 column table.


17

\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} \...


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 ...


14

Assuming that the first row is the name of the columns, then you simply need to load the database via \DTLloaddb{myDB}{MyData.csv} where the file MyData.csv contains the contents as shown above, and the you can use the internal function \DTLdisplaydb{myDB} to print it as a table. This table is very wide so I used the geometry package to extend the width of ...


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}} } \...


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 ...


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>}{&...


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]{$...


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

When using \DTLforeach with \hline it's generally better to use the following schematic structure which puts the \\ and the \hline at the beginning of each non-initial row instead of at the end of each row. \DTLforeach{<database>}{<assignments>}{% \DTLiffirstrow{}{\\\hline} rest of table with no final \\ } For your second problem, there may ...


10

The problem lies with the trailing spaces in your CSV currency values. Because of them, the numbers are treated as strings and the internal conversion from currency to decimal that takes place fails. So with the following CSV: a,"$100,090.06","$107,578.03",0.129565278 b,"$267,697.13","$72,463.54",0.087442318 c,"$761,314.81","$192,210.83",0.231820008 some ...


10

\DTLforeach visits the rows one after another. Therefore the row order of the data base matters: \DTLforeach*[\DTLisSubString{#2}{\RowID}]{#1}{% % #2 = list of rowIDs In the following solution I have put the data extraction in a for loop that iterates over the given row IDs. There are many for loops, e.g. LaTeX's \@for. I am using \comma@parse from ...


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\...


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 ...


9

(La)TeX tabulars do not require a predefined number for the rows. For the columns, however, this is required in the general setup. You can combine column specifications that are similar though using a *{<num>}{<col spec>} specification. This would repeat <col spec> a total of <num> times. Therefore, defining \begin{tabular}{ | *{14}{...


9

Both datatool and pgfplotstable can do similar things, but datatool is designed as a more general tool and therefore can in principle do more things (e.g. form letters and the like). So if your requirements are simply pretty printing tables directly from CSV files I might prefer pgfplotstables since it is especially designed for that, and if you are ...


9

Maybe you want to give LuaLaTeX a try. It's very easy to write a script to read external files and format LaTeX commands. It is good practice to write the lua functions in a separate file with the extension .lua. For this MWE I use the filecontents environment instead to provide an extra file for the lua script and the datafile. Here is an other example for ...


9

There's no problem to do this with the datatool package and siunitx as well. Here's your example done in that way: \documentclass{article} \usepackage{datatool} \usepackage{siunitx} \usepackage{booktabs} % for nicer tables \usepackage{caption} % improve caption spacing (among other things) \usepackage{bm} \renewcommand*\dtldisplaystarttab{\toprule} \...


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 ...


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} \...


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 \...


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

The answer is just \DTLrowcount{Table} I'm sorry. I was looking for it in the documentation, but i was reading after the section "creating a new database" ... :(


8

I checked the datatool manual and found the following note about \DTLnewdbentry (page 32): The value isn’t expanded by default, but you can change this using the declaration: \dtlexpandnewvalue. This can be localised by placing it in a group, or you can switch back using: \dtlnoexpandnewvalue. I simply rewrote \myCom: \newkeycommand{\myCom}[op=1]{% \...


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

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 ...


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,...


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 ...


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,...


Only top voted, non community-wiki answers of a minimum length are eligible