# \write18 encoding

I wrote a bash script osmimage (source for tests), that downloads a map given by an address. I want to write a package that calls this script with \write18, but there are a few problems.

The following example works with lualatex:

\documentclass{article}
%\usepackage[latin1]{inputenc}
%\usepackage[T1]{fontenc}
\usepackage{graphicx}
\def\loc{Bergheimer Straße 110A, 69115 Heidelberg, Germany}
%\def\loc{Rathausmarkt 1, 20095 Hamburg, Deutschland}
\newcommand*\getmap%
{%
%\immediate\write18{osmimage -l "\loc"}
\immediate\write18{osmimage -l "\unexpanded\expandafter{\loc}"}
}%
\begin{document}
\section{Example}
Did you ever wanted to visit the Dante e.V. office? Here we go:

\getmap
\begin{center}
\includegraphics[width=10cm]{osmimage}
\end{center}
\end{document}


Code edited after Ulrike's comment. Still a problem with pdflatex and other encoding than utf-8!

If i run this file with pdflatex (with inputenc and fontenc) the transfer of the address no longer works. Without inputenc or fontenc i get all kinds of strange output in the URL (see log).

If i use an ASCII-only address like the Hamburg town hall, it also works with pdflatex!

So there seems to be some kind of encoding problem as the script expects UTF-8 or maybe url-encoding.

Any idea? It wouldn't be very nice to limit the package to lualatex or maybe xelatex (not tested yet) utf-8 encoding

-
Try \immediate\write18{osmimage -l "\unexpanded\expandafter{\loc}"}. See also tex.stackexchange.com/a/75958/2388 – Ulrike Fischer May 18 '14 at 14:48
Yes, this works with pdflatex and utf8 encoding. There are still encoding problems, when using latin1 instead. Anyway, thank you very much, Mrs.(!!!) Fischer ;-) – Josef May 18 '14 at 15:54
@Josef I guess the script expects the address in UTF-8 encoding. Unless you modify it to interpret Latin-1, you're out of luck. – egreg May 18 '14 at 16:13

Package stringenc can convert the address string from latin1 to utf-8, needed by osmimage:

\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{graphicx}
\usepackage{stringenc}
\def\loc{Bergheimer StraXe 110A, 69115 Heidelberg, Germany}
%\def\loc{Rathausmarkt 1, 20095 Hamburg, Deutschland}
\newcommand*\getmap{%
\StringEncodingConvert{\locstring}{%
\detokenize\expandafter{\loc}%
}{latin1}{utf-8}%
\StringEncodingSuccessFailure{% success
}{% failure
\errmessage{Converting to UTF-8 failed}%
}%
\immediate\write18{osmimage -l "\locstring"}
}%
\begin{document}
\section{Example}
Did you ever wanted to visit the Dante e.V. office? Here we go:

\getmap
\begin{center}
\includegraphics[width=10cm]{osmimage}
\end{center}
\end{document}


-
Works like a charm! Thank you! – Josef May 18 '14 at 19:25