2

I have a small macro that I use to help me build some links. This below is a very simplified version of the problem. Some links have # in the URL. So I had to escape # using \#.

This works ok in PDF generated. But when I compile to HTML, the dash before the # remains there and so in the HTML generated by tex4ht, the URL is not valid.

If I do not escape the # then latex complains.

The actual URL I am using an example is https://groups.google.com/forum/#!forum/fricas-devel

Here is MWE, with output by pdflatex and output by make4ht

\documentclass[11pt]{article}
\usepackage{hyperref}

\newcommand{\addEntry}[1]
{%  
    \url{#1} 
}%

\begin{document}
Here is a link to a computer algebra FriCAS google news group:

\addEntry{https://groups.google.com/forum/\#!forum/fricas-devel}
\end{document}

Here is result in the PDF

Mathematica graphics

Here is the result from make4ht foo.tex (screen shot of the HTML page generated)

Mathematica graphics

You see that the \ is stuck there. This means when I click on the link, it does not work. When I click on it, the Browser changes the link this

    https://groups.google.com/forum//#!forum/fricas-devel

So there is an extra // when only one should be there / so I have to each time manually erase one / from the URL to make it work.

Here is the raw HTML generated by make4ht

<?xml version="1.0" encoding="iso-8859-1" ?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<!--http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd-->  
<html xmlns="http://www.w3.org/1999/xhtml"  
> 
<head><title></title> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
<meta name="generator" content="TeX4ht (http://www.tug.org/tex4ht/)" /> 
<meta name="originator" content="TeX4ht (http://www.tug.org/tex4ht/)" /> 
<!-- xhtml,html --> 
<meta name="src" content="foo.tex" /> 
<link rel="stylesheet" type="text/css" href="foo.css" /> 
</head><body 
>
<!--l. 11--><p class="noindent" >Here is a link to a computer algebra FriCAS google news group:
</p><!--l. 13--><p class="indent" >   <a 
href="https://groups.google.com/forum/\#!forum/fricas-devel" class="url" ><span 
class="cmtt-10x-x-109">https://groups.google.com/forum/\#!forum/fricas-devel</span></a> </p> 
</body></html> 

I am using texlive 2016

make4ht -version
make4ht version 0.1b

which make4ht
/usr/local/texlive/2016/texmf-dist/scripts/make4ht/make4ht

How to fix this so that tex4ht will not keep the \ in there link in the PDF?

6
  • At least with your MWE you can just use #! in the url with pdflatex and press enter when the ! Illegal parameter number in definition of \Hy@tempa. messages show up. The document compiles fine.
    – Skillmon
    Commented May 10, 2017 at 23:02
  • @Skillmon The build is done using Makefiles, so I can't really press enter and such manually as the build will stop otherwise when I am not on the terminal. But thanks for the information.
    – Nasser
    Commented May 10, 2017 at 23:04
  • Then use the following in your Makefile's target (at least in the meantime): pdflatex -interaction nonstopmode file.tex
    – Skillmon
    Commented May 10, 2017 at 23:08
  • @Skillmon but would this not stop the build when a real error shows up? I have large tree and I want the build to stop on an error so I can fix it. If I tell the build to keep going, I will not see any errors that show. But I think a fix should be done at source level. I do not like these workarounds a problem.
    – Nasser
    Commented May 10, 2017 at 23:10
  • Me neither. But since I don't know a proper solution atm. this workaround does the trick in the meantime...
    – Skillmon
    Commented May 10, 2017 at 23:13

2 Answers 2

3

I think best solution would be to enable insertion of unescaped # character as parameter to your custom macro:

\documentclass[11pt]{article}
\usepackage{hyperref}

\newcommand{\addEntry}[1]
{%  
  \expandafter\url\expandafter{\detokenize{#1}}%
}%

\begin{document}
Here is a link to a computer algebra FriCAS google news group:

\addEntry{https://groups.google.com/forum/#!forum/fricas-devel}
\end{document}

This works both with pdflatex and tex4ht:

enter image description here

3
  • Funny, I tried that (\detokenize) and it didn't work out... Maybe I was missing one \expandafter (I don't remember the exact code I tried).
    – Skillmon
    Commented May 11, 2017 at 10:34
  • @Skillmon I was actually quite surprised that it started to work with \expandafter :)
    – michal.h21
    Commented May 11, 2017 at 11:01
  • I was pretty sure it should work with \expandafter but was disappointed, that it didn't work (I think I only had the first one, which resulted in detokenizing #1...).
    – Skillmon
    Commented May 11, 2017 at 14:13
1

There is a solution to your problem, but I do not succeed in building it into \addEntry. The solution is to (locally) change the \catcode of #:

\documentclass[11pt]{article}
\usepackage{hyperref}

\newcommand{\addEntry}[1]
{%  
    \url{#1} 
}%

\begin{document}
Here is a link to a computer algebra FriCAS google news group:

\begingroup
\catcode`\#=11
\addEntry{https://groups.google.com/forum/#!forum/fricas-devel}
\endgroup
\end{document}

You must log in to answer this question.

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