Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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!

map wuth Dante e.V. office

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!

map Hamburg town hall

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

share|improve this question
    
Try \immediate\write18{osmimage -l "\unexpanded\expandafter{\loc}"}. See also tex.stackexchange.com/a/75958/2388 –  Ulrike Fischer May 18 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 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 at 16:13

1 Answer 1

up vote 4 down vote accepted

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}

Result

share|improve this answer
    
Works like a charm! Thank you! –  Josef May 18 at 19:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.