I'm trying to create a new command in LaTeX that creates a Google Map URL pointing to the coordinates associated with the place specified as a parameter in the called command (a sort of "table lookup" function). The places and the relative coordinates are stored inside a coords.CSV file, and must be read using the datatool package.
The Google Map URL should be structured like this one:
https://www.google.com/maps/?q=<LAT>,<LNG>
where <LAT> and <LNG> are the latitude and longitude coordinates loaded from the coords.CSV file, which is structured in this way:
Place,LAT,LNG
Test,42.0000,42.0000
...
This is how the command was defined:
\usepackage{datatool}
\newcommand{\coords}[1]{
% Loads the CSV
\DTLsetseparator{,}
\DTLloaddb{coords}{doc/coords.csv}
% Assigns the coordinates to the variables \LAT and \LNG, relative to specific place (the parameter #1)
\def \LAT {\DTLfetch{coords}{Place}{#1}{LAT}}
\def \LNG {\DTLfetch{coords}{Place}{#1}{LNG}}
% Generates the URL pointing to Google Maps
Place: \href{https://www.google.com/maps/?q=\LNG ,\LNG}{#1}
}
Finally, I use the new command in this way:
\coords{Test}
I've managed to correctly load the coordinates of the place called inside the command (in this case "Test"), but when I try to generate the URL, LaTeX gives me a lot of errors, most of which are ! Undefined control sequence. If I remove \LAT and \LNG from the line where the URL is generated (inside the command definition), I don't get any error, but of course the URL does not contain any coordinates, since they are stored inside the \LAT and \LNG variables.
Is there a way to properly generate the URL using the defined variables inside the \href command?
This is a test example:
\documentclass[a4paper,10pt]{article}
\usepackage{hyperref}
\usepackage{datatool}
\newcommand{\coords}[1]{
% Loads the CSV
\DTLsetseparator{,}
\DTLloaddb{coords}{coords.csv}
% Assigns the coordinates to the variables \LAT and \LNG, relative to specific place (the parameter #1)
\def \LAT {\DTLfetch{coords}{Place}{#1}{LAT}}
\def \LNG {\DTLfetch{coords}{Place}{#1}{LNG}}
% Generates the URL pointing to Google Maps
Place: \href{https://www.google.com/maps/?q=\LAT ,\LNG}{#1}
}
\begin{document}
\coords{Test}
\end{document}
coords.csv:Place,LAT,LNG Test,42,42I think it shouldn't be too difficult to recreate a csv file with just 2 lines. – Trial4life Dec 04 '20 at 10:23filecontents*env (it takes a mandatory filename as its argument) – daleif Dec 04 '20 at 10:25