2

I would like to replace blank lines in a command by the newline character \textCR.

For example:

\documentclass{article}
\usepackage{pdfcomment}

\mypdfcomment[2][]{\pdfcomment[#1]{#2}}

\begin{document}
  \mypdfcomment{first line

  second line}
\end{document}

Here I would like

\mypdfcomment{first line

  second line}

to produce

\pdfcomment{first line\textCR second line}

Background: pdfcomment does not understand blank lines and instead uses \textCR. It would be good not having to care about.

2
  • 1
    Please make a complete example, including the definition of \mypdfcomment – egreg Sep 23 '16 at 8:19
  • @egreg The idea was just to have \mypdfcomment do the same as \pdfcomment except for the replacement of the empty lines. Maybe you know what is going wrong in trying to use the solution below to replace \newline and `\` as well (see comments)? – Daniel Sep 23 '16 at 9:23
6

Like this?

\documentclass{article}
\usepackage{pdfcomment}

\newcommand\mypdfcomment[2][]{{%
    \let\par\textCR
    \pdfcomment[#1]{#2}%
  }}

\begin{document}
  \mypdfcomment{first line

  second line}
\end{document}
4
  • Thanks a lot! And my limited LaTeX knowledge was enough to recover the optional argument. So I am using \newcommand{\mypdfcomment}[2][]{\bgroup \let\par\textCR \pdfcomment[#1]{#2}\egroup}. Is there a particular reason you introduced the domypdfcomment? Or was it just to make the code clearer? – Daniel Sep 23 '16 at 8:49
  • I realised that there are a couple of additional line breaks in LaTeX to take care of. I tried to include them like this: \newcommand{\mypdfcomment}[2][]{\bgroup \let\par\textCR \let\newline\textCR \let\\\textCR \pdfcomment[#1]{#2}\egroup}. But it doesn't work. Any idea on this? – Daniel Sep 23 '16 at 9:04
  • 1
    @Daniel No idea why this does not work. I edited my answer to reflect your desired solution. The two-stage macro was a leftover from a previous attempt, I removed it. – Henri Menke Sep 23 '16 at 9:16
  • My guess is that it does not work because \pdfcomment already removes the \newline somehow. Notice that a blank line in \pdfcomment leads to en error while \newline does not and makes no change. – Daniel Sep 23 '16 at 11:24

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.