1

Some users on the main Tex-chatroom of this site (one using TeX Live) have reported that this (or similar) code IS outputting clickable URLs for them, while for me (using TeXShop), it ISN'T ... What could be the problem?

MWE

\documentclass[a4paper]{article}
\usepackage{xparse, hyperref}

\ExplSyntaxOn
\cs_set_eq:NN
\IfEmptyTF
\tl_if_blank:nTF
\ExplSyntaxOff

\NewDocumentEnvironment {mainentry} { m m m } {%
  \IfEmptyTF{#3}{
First argument returns #1 NO
  }{%
Second argument returns #2 YES
  }%
  }{%
  \href{http://a.beautiful.url/?searchid=#1}{Click on me}%
}

\begin{document}

A) There should be a YES here. OK.

\begin{mainentry}{
first
}{
second
}{
third
}
\end{mainentry}

B) There should be a NO here. OK.

\begin{mainentry}{
first
}{
second
}{
%
}
\end{mainentry}

\end{document}
8
  • There is still a space in the third arg in B right after the {, same with the others
    – daleif
    Commented Oct 8, 2017 at 6:07
  • @daleif Did you mean to write this with regards to the original question (OP), or with regards to my answer?
    – O0123
    Commented Oct 8, 2017 at 6:17
  • Both, the % at the end does not help much when there is also an unwanted space at the start of the arg right after the {
    – daleif
    Commented Oct 8, 2017 at 9:32
  • @daleif But, as far as my answers go, I don't see any difference in compiling by adding even more %s, right? I believe there are no more compiling problems with the two sub-answers I proposed?
    – O0123
    Commented Oct 8, 2017 at 9:38
  • Not at a pc so I cannot test. I'd like to know if there is a difference between if_blank from xparse and ifblank from etoolbox. The later should detect blank arg in case B. But what exactly is your issue here? Have you tested the pdf in something else than the pdf viewer from texshop?
    – daleif
    Commented Oct 8, 2017 at 9:42

2 Answers 2

1

Just in addition to Manuels comment

\ExplSyntaxOn
\cs_set_eq:NN\IfEmptyTF\tl_if_blank:nTF
\cs_set_eq:NN\Trim\tl_trim_spaces:n
\ExplSyntaxOff

\NewDocumentEnvironment {mainentry} { m m m } {%
  \IfEmptyTF{#3}{
    ... 3 is empty
  }{%
    ... 3 is not empty
  }%
  {%
    \typeout{'#1'}% just to verify
    \edef\temp{\Trim{#1}}
    \typeout{'\temp'}% just to verify
    \expandafter\href\expandafter{http://a.beautiful.url/?searchid=\temp}{Click
      on me}%
  }
}

The rest of the code is the same as in the OPs

2

The problem here are the spaces. Following User daleif's good suggestion (comment to OP) to check the PDF-output with different viewers, I analyzed the following, when opening the PDF-output from the OP (all on Mac):

  • TeXShop 3.88: no sign of any hyperlink
  • Safari 11.0: no sign of any hyperlink
  • Adobe Acrobat Reader DC 17.012.20098: outputs a clickable hyperlink, namely http://a.beautiful.url/?searchid=%20first%20 instead of http://a.beautiful.url/?searchid=first

Wherein %20 is the percent-encoding of a space.

One example which solves the problem is by changing the syntax layout of e.g.

Original

\begin{mainentry}{
first
}{
second
}{
third
}
\end{mainentry}

into

Solution 1

\begin{mainentry}
{first}
{second}
{third}
\end{mainentry}

Which I actually find very bothersome, because when copy-pasting manual lines (in this case, for example, of content "first", "second", "third"), it's much easier to paste them into empty lines (cf. Original) than to paste them between curly brackets (cf. Solution 1).

To solve at least half of the problem, then, one could propose Solution 2, where by inserting some instances of % we can at least keep one side of the blank lines empty before pasting anything into them:

Solution 2

\begin{mainentry}{%
first%
}{
second%
}{
third%
}
\end{mainentry}
2
  • Solution three would be to put \tl_trim_spaces:n inside the argument so whatever the spaces they are removed.
    – Manuel
    Commented Oct 8, 2017 at 12:36
  • @Manuel How exactly to arrange all the syntax correctly? I would be interested in an answer following that strategy, if you could post one?
    – O0123
    Commented Oct 8, 2017 at 13:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .