1

I've already tried 10 billion advices like using \usepackage{grffile}, wrapping the filename into {} and/or "" (in any combination). Nothing is working!

So, I have a file with path plots/task-1/ABC123_/qa_pt:0.20-2.00/VtxZ (-10.00, 10.00)/charged; eta (-0.80, 0.80)/FB: 16; eta (-0.80, 0.80)/eff/eta_phi.pdf and I need to include it into beamer presentation, which is compiled by LuaLaTeX (if it is important).

Changing the path is not an option I can live without spaces (but can't without dots and underscores), but it is better to keep them, and there are multiple files with the same name but different paths which need to be used.

Minimal non-working example (find any .pdf file to include and place it at the path):

\documentclass[aspectratio=1610,10pt]{beamer}

\begin{document}

\begin{frame}
    \includegraphics{plots/task-1/ABC123_/qa_pt:0.20-2.00/VtxZ (-10.00, 10.00)/charged; eta (-0.80, 0.80)/FB: 16; eta (-0.80, 0.80)/eff/eta_phi.pdf}
\end{frame}

\end{document}

The error:

! Missing $ inserted.
<inserted text> 
$
l.10 \end{frame}

? 

! Package luatex.def Error: File `plots/task-1/ABC123_/qa_pt:0.20-2.00/VtxZ (
-10.00, 10.00)/charged; eta (-0.80, 0.80)/FB: 16; eta (-0.80, 0.80)/eff/eta_phi
.pdf' not found: using draft setting.

See the luatex.def package documentation for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.10 \end{frame}

? 
! Missing $ inserted.
<inserted text> 
$
l.10 \end{frame}

?
  • I've cleaned up the comment thread here. – Joseph Wright Mar 7 '18 at 17:24
4

This works in pdflatex but fails in the lua part of luatex's inclusion (this must be the most crazy filename ever seen:-)

\documentclass[aspectratio=1610,10pt]{beamer}

\begin{document}

\begin{frame}
    \includegraphics{"plots/task-1/ABC123_/qa_pt:0.20-2.00/VtxZ (-10.00, 10.00)/charged; eta (-0.80, 0.80)/FB: 16; eta (-0.80, 0.80)/eff/eta_phi".pdf}
\end{frame}

\end{document}

This version works in lualatex and pdflatex

\documentclass[aspectratio=1610,10pt]{beamer}

\begin{document}

\begin{frame}
    \includegraphics{eta_phi.pdf}
\end{frame}

\end{document}

To ensure the file is found prepend the plots directory to the input path for example this commandline works:

 TEXINPUTS=./plots//: lualatex mainfile

as (assuming bash shell) this locally sets TEXINPUTS to search all directories under plots


If you really have painted yourself into a corner with duplicated filenames in "interesting" directory paths then this does work in lualatex

\documentclass[aspectratio=1610,10pt]{beamer}

\makeatletter
\def\Gread@@pdftex#1{%
  \edef\Gin@attr@hash{%
    \ifx\Gin@pagebox\@empty
    \else
      :\Gin@pagebox
    \fi
    \ifx\Gin@page\@empty
    \else
      :P\Gin@page
    \fi
    \ifx\Gin@decode\@empty\else
      :D[\Gin@decode]%
    \fi
    \ifGin@interpolate
      :I%
    \fi
  }%
  \@ifundefined{#1 image\Gin@attr@hash}%
    {%
      \saveimageresource
        \ifnum0%
          \ifx\Gin@decode\@empty\else 1\fi
          \ifGin@interpolate 1\fi
          >0 %
          attr{%
            \ifx\Gin@decode\@empty\else/Decode[\Gin@decode]\fi
            \ifGin@interpolate/Interpolate true\fi
          }%
        \fi
        \ifx\Gin@page\@empty\else page \Gin@page\fi
        \Gin@pagebox
        {\expandafter\zz#1}%
      \setbox\@tempboxa=\hbox{\useimageresource\lastsavedimageresourceindex}%
      \def\Gin@llx{0}\let\Gin@lly\Gin@llx
      \Gin@defaultbp\Gin@urx{\wd\@tempboxa}%
      \Gin@defaultbp\Gin@ury{\ht\@tempboxa}%
      \expandafter\xdef\csname #1 image\Gin@attr@hash\endcsname
        {\useimageresource\the\lastsavedimageresourceindex}%
      \expandafter\xdef\csname #1 height\Gin@attr@hash\endcsname
        {\the\ht\@tempboxa}%
      \expandafter\xdef\csname #1 width\Gin@attr@hash\endcsname
        {\the\wd\@tempboxa}%
      \Gin@log{%
        <#1, %
        id=\the\lastsavedimageresourceindex, %
        \ifx\Gin@page\@empty\else page=\Gin@page , \fi
        \ifx\Gin@pagebox\@empty\else\ifx\Gin@pagebox\GPT@cropbox\else
          pagebox=\Gin@pagebox , \fi\fi
        \ifx\Gin@decode\@empty\else decode=[\Gin@decode], \fi
        \ifGin@interpolate interpolate=true, \fi
        \the\wd\@tempboxa\GPT@space x \the\ht\@tempboxa
        >%
      }%
    }{%
      \def\Gin@llx{0}\let\Gin@lly\Gin@llx
      \Gin@defaultbp\Gin@urx{\csname #1 width\Gin@attr@hash\endcsname}%
      \Gin@defaultbp\Gin@ury{\csname #1 height\Gin@attr@hash\endcsname}%
    }%
}

\def\zz"#1"{#1}
\begin{document}

\begin{frame}

    \includegraphics{"plots/task-1/ABC123_/qa_pt:0.20-2.00/VtxZ (-10.00, 10.00)/charged; eta (-0.80, 0.80)/FB: 16; eta (-0.80, 0.80)/eff/eta_phi".pdf}
%    \includegraphics{eta_phi.pdf}
\end{frame}

\end{document}
  • It is really cool that it works in pdflatex, but what should I do when it will fail due to pgfplots with dozens of plots? As for TEXINPUTS, I have multiple such files under the ./plots/ tree. – LaTeX rulez Mar 7 '18 at 16:48
  • 5
    @Latexsucks (a) you should consider changing your user name if you want people to help, it's not particularly polite and (b) the version I posted will work if you have thousands of files under plots why does that matter, so long as they have distinct names. – David Carlisle Mar 7 '18 at 16:50
  • I won't be able to change my name until 6th of April, because I've changed it after I've asked this question. – LaTeX rulez Mar 7 '18 at 16:53
  • @Latexsucks well as I say it's a disincentive for people to help, but up to you. – David Carlisle Mar 7 '18 at 16:54
  • 1
    @Latexsucks see update – David Carlisle Mar 7 '18 at 17:23
1

To include the file, write in your preable

\makeatletter
\def\Gin@getbase#1{%
  \edef\Gin@base{\filename@area\filename@base}%
  \edef\Gin@ext{#1}%
}
\makeatother

This should be a last resort. I strongly recommend finding a way to use saner filenames instead.

EDIT: With this, the whole file should look like

\documentclass[aspectratio=1610,10pt]{beamer}
\makeatletter
\def\Gin@getbase#1{%
  \edef\Gin@base{\filename@area\filename@base}%
  \edef\Gin@ext{#1}%
}
\makeatother

\begin{document}

\begin{frame}
  \includegraphics{plots/task-1/ABC123_/qa_pt:0.20-2.00/VtxZ (-10.00, 10.00)/charged; eta (-0.80, 0.80)/FB: 16; eta (-0.80, 0.80)/eff/eta_phi.pdf}
\end{frame}

\end{document}
  • Should I use braces/quotes around the file name with your solution? – LaTeX rulez Mar 7 '18 at 17:08
  • No, that should not be necessary. – Marcel Krüger Mar 7 '18 at 17:10
  • I've included your code after \documentclass and before \begin{document} and I get ! Missing $ inserted. – LaTeX rulez Mar 7 '18 at 17:12
  • did you test this with luatex on the suggested filename? – David Carlisle Mar 7 '18 at 17:15
  • @DavidCarlisle I did, it works on my system. I just updated my TeXLive, so maybe it doesn't work with older packages? – Marcel Krüger Mar 7 '18 at 17:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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