tex4ht
supports configuration file, where you can provide custom definitions for various commands. In your place, I would use a macro that holds the base path for your \href
commands. In the configuration file, it can be redefined to point to another directory, or to completely different web page.
Simple example:
\documentclass{article}
\usepackage{hyperref}
\newcommand\hrefroot{somedirectory/}
\begin{document}
Hello \href{\hrefroot report.pdf}{report}
\end{document}
Custom command \hrefroot
is introduced. It holds the path to file and it must be used in all \href
commands. The configuration file for tex4ht
can look like this:
\Preamble{xhtml}
\ifOption{external}{\renewcommand\hrefroot{https://www.report.com/}}{\renewcommand\hrefroot{report/}}
\begin{document}
\EndPreamble
The important line is
\ifOption{external}{\renewcommand\hrefroot{https://www.report.com/}}{\renewcommand\hrefroot{report/}}
the rest is only required structure of the configuration file. The \ifOption
command checks for option which can be specified on the command line. If this option is used, then the \hrefroot
is redefined to point to external site, report
directory is used otherwise.
Basic way to compile the document is the following:
make4ht -c configfilename.cfg filename.tex
You can specify the external
option using the following syntax:
make4ht -c configfilename.cfg filename.tex "external"
And here is the result for both options:
<!--l. 5--><p class="noindent" >Hello <a
href="report/report.pdf" >report</a>
</p>
and for external
:
<!--l. 5--><p class="noindent" >Hello <a
href="https://www.report.com/report.pdf" >report</a>
</p>
\href
or\url
commands, or they come from\ref
etc?The \href{somedirectory/report.pdf}{report} shows what I mean.
I'd this option:The \href{https://www.report.com/report.pdf}{report} shows what I mean.
I'd like to do this without having to recode (I have over a hundred links). I would like a single input LaTeX file that allows both options/versions. Do you know how to do this?