TransWikia.com

datatool sorting problem - wrong data type?

TeX - LaTeX Asked by susis strolch on June 21, 2021

I created a very small DB with datatool to store two values at each line of the table. First a running ID and second a generated dimension (converted to mm) which I calculated of the width of each input image I am going to register/save in this list.

After all images are registered, I want to sort the list first before I further process it. Unfortunately, DTLsort seams to interprets the number not as numbers but something else and so the resulting sorted list is not as expected.

As which data type do I need to insert the values of the image dimensions into the DB so that DTLsort can sort them correctly? Or is there any switch/flag I need to set so that DTLsort knows how to interpret the values of the column?
Here is what I got so far:

documentclass{article}
usepackage{datatool}
usepackage{graphicx}

defdimtomm#1{thenumexprdimexpr#1relax*635/118407168relax}

newsaveboximagebox
newcommand{regimg}[2]{%
  sbox{imagebox}{includegraphics[height=5cm]{#1}}%
  DTLnewrow{list}%
  dtlexpandnewvalue%
  DTLnewdbentry{list}{label}{#2}%
  DTLnewdbentry{list}{width}{dimtomm{wdimagebox}}%
}

newenvironment{sortedlist}{%
  DTLifdbexists{list}{DTLcleardb{list}}{DTLnewdb{list}}%
  DTLifdbexists{lists}{DTLcleardb{lists}}{DTLnewdb{lists}}%
}{%  
DTLsort{width=descending}{list}
DTLdisplaydb{list}
}

begin{document}
begin{sortedlist}
regimg{img01.jpg}{1}
regimg{img02.jpg}{2}
regimg{img03.jpg}{3}
regimg{img04.jpg}{4}
%...
end{sortedlist}
end{document}

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP