# different result from tex4ht vs. pdf when using macro call

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}

{%
\url{#1}
}%

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

\end{document}


Here is result in the PDF

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

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"
>
<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" />
>
<!--l. 11--><p class="noindent" >Here is a link to a computer algebra FriCAS google news group:
</p><!--l. 13--><p class="indent" >   <a
</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?

• 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 May 10 '17 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 May 10 '17 at 23:04
• Then use the following in your Makefile's target (at least in the meantime): pdflatex -interaction nonstopmode file.tex – Skillmon May 10 '17 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 May 10 '17 at 23:10
• Me neither. But since I don't know a proper solution atm. this workaround does the trick in the meantime... – Skillmon May 10 '17 at 23:13

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

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

{%
\expandafter\url\expandafter{\detokenize{#1}}%
}%

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

\end{document}


This works both with pdflatex and tex4ht:

• 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 May 11 '17 at 10:34
• @Skillmon I was actually quite surprised that it started to work with \expandafter :) – michal.h21 May 11 '17 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 May 11 '17 at 14:13

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}

\catcode\#=11
`