Bug Tracker
I’m currently working on a major new version of the datatool package. This may take a while. Please be patient. (Experimental version available for testing.)
ID | 223🔗 |
---|---|
Date: | 2023-04-16 14:41:06 |
Last update: | 2023-04-17 08:46:20 |
Status | Open Sign in if you want to bump this report. |
Category | datatool |
Version | 2.32 |
Summary | Using datatool methods with hyperref package |
Sign in to subscribe to notifications about this report.
Description
Hello,I use datatool package to load data from csv. Also I display some csv values in TOC. As Ulrike Fischer mentioned the methods of datatool is not expandable, that is why hyperref reports its warning: Token not allowed in a PDF string.
Ulrike Fischer provided a solution (https://tex.stackexchange.com/a/682971/294709) but it requires another temporary storage for my data and extra NewExpandableDocumentCommand to maintaine on my side. I think it would be nice to add new or update existing methods in datatool package to make it compatible with hyperref package based on Ulrike Fischer recommendation.
(Additionally Overleaf has some parsing issue with Ulrike Fischer's code. Overleaf reports: Your code has errors that need to be fixed before the auto-compile can run. It compiles and generates valid and correct PDF file with correct bookmarks, but auto-compile feature is really OFF.)
Here is the details and sample of my issue (https://tex.stackexchange.com/q/682941/294709):
I am using datatool to read csv file and get values from it. I also want to use these values in a chapter names. I have no problems with TOC and pages. I can see values from my csv file. But bookmarks create by hyperref (I think) have only PK/indexes, but not values from csv file.
Additionally I have got this warning: Package hyperref Warning: Token not allowed in a PDF string.
My values in csv file have only A-Za-z0-9 letters and not special Unicode symbols like \sqrt.
Here is my sample code that can show the issue.
%&xelatex
% !TEX program = xelatex
\documentclass{book}
\usepackage{polyglossia}
\usepackage{fontspec}
\usepackage{noto-mono} % to support hyperref package
\usepackage{amsmath,amsthm,amssymb,mathrsfs,amsfonts,dsfont}
\usepackage{hyperref}
\hypersetup{
colorlinks=true,
linkcolor=blue,
filecolor=magenta,
urlcolor=blue,
}
\usepackage{datatool}
\author{Some}
\title{Any}
\begin{filecontents*}{data.csv}
PK,Value
1,Val1
2,Val2
\end{filecontents*}
\DTLloaddb{values}{data.csv}
\ExplSyntaxOn
\NewDocumentCommand{\getValue}{m}{\DTLfetch{values}{PK}{#1}{Value}}
\ExplSyntaxOff
\begin{document}
\frontmatter
\tableofcontents
\mainmatter
\chapter{AAA \getValue{1}}
\chapter{BBB \getValue{2}}
\end{document}
Thank you for creating and maintaining such a great package!
--
Sergiy Zinovyev
I am working on a book for Ukrainian students:
http://nebayduzhi-math.azurewebsites.net
MWE
Download (775B)
%&xelatex % !TEX program = xelatex \documentclass{book} \usepackage{polyglossia} \usepackage{fontspec} \usepackage{noto-mono} % to support hyperref package \usepackage{amsmath,amsthm,amssymb,mathrsfs,amsfonts,dsfont} \usepackage{hyperref} \hypersetup{ colorlinks=true, linkcolor=blue, filecolor=magenta, urlcolor=blue, } \usepackage{datatool} \author{Some} \title{Any} \begin{filecontents*}{data.csv} PK,Value 1,Val1 2,Val2 \end{filecontents*} \DTLloaddb{values}{data.csv} \ExplSyntaxOn \NewDocumentCommand{\getValue}{m}{\DTLfetch{values}{PK}{#1}{Value}} \ExplSyntaxOff \begin{document} \frontmatter \tableofcontents \mainmatter \chapter{AAA \getValue{1}} \chapter{BBB \getValue{2}} \end{document}
Evaluation
This isn't really a bug as most of the database commands are too complex to be expandable, which is what's needed in this situation. In the next version I will make fragile commands robust and will try to provide expandable alternatives, where possible, but it won't always be possible. In the case of \DTLfetch
, it first attempts to fetch the relevant row index using \dtlgetrowforvalue
(which in turn uses \dtlgetrowindex
) and then \DTLfetch
uses \dtlgetentryfromcurrentrow
to get the required column value.
Unfortunately, the only way of dealing with this is to fetch the value first into a temporary control sequence and use that instead. For example:
\DTLassignfirstmatch{values}{PK}{1}{\Value=Value} \chapter{AAA \Value} \DTLassignfirstmatch{values}{PK}{2}{\Value=Value} \chapter{BBB \Value}(NB take care you don't use the name of an existing command. In the above I've used
\Value
with a leading capital, which isn't defined by the LaTeX kernel, but it may be defined by something else. Don't use \value
, which is defined by the kernel.)Comments
0 comments.
Add Comment
Page permalink: https://www.dickimaw-books.com/bugtracker.php?key=223