0

This question is related to a previous question regarding machine readability of a PDF generated using moderncv.

I'm trying add some hidden description within the PDF, so the information is not visible or printable on the PDF, but it's there on the copy-paste text extraction or through pdftotext. So far, the best way has been through transparency, using the transparent package. However, I'm getting errors when I try to add transparent characters within some macros.

! Undefined control sequence.
\transparent ...n@ =\z@ \def \x {0}\else \edef \x 
                                                  {\strip@pt \dimen@ }\edef ...

followed by the line that calls the macro where I'm trying to put transparent chars.

I'm using pdflatex. Here's my MWE (non-working, because of the errors):

\documentclass{article}
\usepackage{transparent}

\begin{document}
\section{First example}
Hello \texttransparent{0}{THIS IS FUNNY~}world

\section{Second example}
Hello \makebox[0pt]{\texttransparent{0}{THIS IS FUNNY~}}world

%the next line gives error
\section{Third \makebox[0pt]{\texttransparent{0}{ERROR~}}example}
This one gives error

%the next line gives error
\section{\texorpdfstring{Fourth \makebox[0pt]{\texttransparent{0}{ERROR~}}example}{Fourth example}}
Also error
\end{document}

Like I said at the beginning, my issue is with the moderncv macros and transparency. But I hope that understanding/fixing the errors in this MWE will help me address the ones on my document. Do I need to patch the section macro from article?. Or call the transparency in a different way

As always, thanks to the community for its help.

1

The \makebox and \texttransparent are expanded when they are written to the .toc file to create the table of contents. You just have to \protect these macros when they are used in fragile contexts, like section headers:

\documentclass{article}
\usepackage{transparent}
\usepackage{hyperref}% You need to load hyperref to use \texorpdfstring

\begin{document}
\section{First example}
Hello \texttransparent{0}{THIS IS FUNNY~}world

\section{Second example}
Hello \makebox[0pt]{\texttransparent{0}{THIS IS FUNNY~}}world

%the next line gives error
\section{Third \protect\makebox[0pt]{\protect\texttransparent{0}{ERROR~}}example}
This one gives error

%the next line gives error
\section{\texorpdfstring{Fourth \protect\makebox[0pt]{\protect\texttransparent{0}{ERROR~}}example}{Fourth example}}
Also error
\end{document}
  • Thanks!. How can I tell if this use of protect will work on my actual document with moderncv macros? – phollox Jul 19 '18 at 11:59
  • 1
    @phollox To know, for sure, only testing. But \protect is part of the LaTeX kernel and is designed for this kind situation, so I guess it will work if the use case is similar. If it doesn't, you can always post a question and link to this one. – Phelype Oleinik Jul 19 '18 at 12:07

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.