# tex4ht: configure href to open in new tab

I'm working with tex4ht (htlatex) and I'm trying to put links into the page it generates. I'm trying to find a way to make it so that when I place a link in the page the link is generated to have the target set to _blank. The reason for this is so that I can have these links open in a new tab. Here is the code I have in the .tex file

\href{www.somesite.com}{The text}


Here is what it generates

<a href="www.somesite.com">The text</a>


Here is what I'd like to generate for all links except the cross links

<a href="www.somesite.com" target="_blank">The text</a>


I know there are ways to use \Configure but I can't seam to make them change the code generation at all.

You can redefine \href command in the custom config file to include that attribute. Create file hello.cfg:

\Preamble{xhtml}

\begin{document}
\makeatletter
\renewcommand{\href}[2]{\bgroup\let~\H@tilde%

\makeatother
\EndPreamble


this definition is modified macro from tex4ht sources. \let~\H@tilde is needed for support urls in form of something.com/~username/whatewer.html.

\Link command has syntax:

\Link[external_url attributes]{internal link}{declare internal link} url text\EndLink


you don't need internal link and declare internal link in your case, it is useful for crossreferences in the document.

compile your document with

htlatex filename hello


and the result:

<!--l. 5--><p class="noindent" ><a
href="http://www.somesite.com" target="_blank" >The text</a>
</p>

• Thank you so much. I've been searching for hours to try to find this solution. May 19 '15 at 14:59
• @MarcusKarpoff you can find basic info about tex4ht configurations and available commands here: michal-h21.github.io/src4ht/tex4ht-infose1.html#x6-30002.1 (see also other pages of that document) May 19 '15 at 15:03
• of course, you must know that you need to redefine the command you want to modify May 19 '15 at 15:04
• In case anyone comes looking. I noticed that it didn't actually work for tildes still. After playing around I found a way to make them work. Just use \string~ and it will place a tilde in think link May 26 '15 at 14:39