0

I'm using the following code:

\usepackage{xstring}
\usepackage{embedfile}

%\newcommand{\underscorefix}[1]{\StrSubstitute{#1}{_}{\_}} <-- not working
\newcommand{\underscorefix}[1]{#1}
\embedfile[filespec=name_1.dat,ucfilespec={\underscorefix{name_1.dat}},mimetype=application/octet-stream]{source_dir_1/name_1.dat}

How can I replace the underscore with backslash underscore for the ucfilespec option?

The reason for that is that I would like to have a command like that:

\newcommand{\datafile}[2]{\embedfile[filespec={#2},ucfilespec={\underscorefix{#2}},mimetype=application/octet-stream]{#1#2}}
  • 2
    Please provide complete MWE. Also, when you say it is "not working," do you mean that compile halts with an error, or that it hangs indefinitely, or that it produces an unexpected result? – user139954 Apr 11 '18 at 15:28
  • 1
    Do you need to escape the underscore? I made an experiment passing name_1.dat to the ucfilespec key and I get this in the (uncompressed) PDF file: <</Type/Filespec/F(name_1.dat)/UF(name_1.dat)/EF<</F 1 0 R>>>> – egreg Apr 11 '18 at 22:21
0

Setting the stringmethod=escape option for \embedfile solved the problem.

Complete code:

\usepackage{embedfile}
\newcommand{\datafile}[2]{\embedfile[filespec={#2},ucfilespec={#2},mimetype=application/octet-stream,stringmethod=escape]{#1#2}}

Now the filespec and the ucfilespec contains underlines. Before just the filespec.

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.