TransWikia.com

References in names and descriptions of embedded files with navigator

TeX - LaTeX Asked on December 22, 2020

I want to attach several files to a document and name them according to the Figure, Table etc. they belong to. I use the navigator package to do this, but I am unable to get it to work properly.

What I want:

documentclass{article}

usepackage{hyperref}
usepackage{navigator}

begin{filecontents*}[overwrite]{attachment.txt}
This is an attachment
end{filecontents*}

begin{document}
section{Section 1}
label{section1}
embeddedfile[Attachment for Section ref{section1}]{attachment}[Sectionref{section1}.txt]{./attachment.txt}
end{document}

If I run this without including the package hyperref, it works on the second run, presumably because the references need to be created first. However, the references in the file name and description are rendered as “Section 1hbox{}”.
If I include the hyperref package, nothing works anymore and I get the follwing errors for the line with embeddedfile:

! Argument of @sect has an extra }.
! Paragraph ended before @sect was complete.

One Answer

I wouldn't use navigator together with hyperref. Both packages try to handle a quite similar set of PDF features, and in a number of places they clash, for example as both write to the catalog and the info dictionary.

If you want to use navigator use it for everything, but be aware that it is missing one important feature of hyperref: It doesn't have an equivalent to pdfstringdef which converts TeX input to something safe in a PDF string.

This leads to your error: ref is a rather complex command, but navigator expects that the description and alternate file name is something simple, that can be handled by pdfescapestring. Using pdfstringdef doesn't work, as then the description is escaped twice.

With embedfile instead of navigator your example could be done like this (here too one need to avoid ref in the filespec).

documentclass{article}

usepackage{hyperref}
usepackage{zref-user}
usepackage{embedfile}

begin{filecontents*}{attachment.txt}
This is an attachment
end{filecontents*}
makeatletter
newcommandexpref[1]{zref@extract{#1}{default}}
makeatother
begin{document}
section{Section 1}
label{section1}zlabel{section1}

embedfile [filespec=Sectionexpref{section1}.txt,
desc=Attachment for Section expref{section1}]{attachment.txt}

end{document}

Answered by Ulrike Fischer on December 22, 2020

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