Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I use Scientific word (SW), which generates Latex, then I process the Latex output using Latex2html (l2h) to generate HTML as the support for HTML is better with l2h than SW (table of contents, break the page into sub pages, etc...)

SW supports the package hyperref but l2h does not.

Hence, when when a hyperlink is added using SW, the code generated reads like this:

\documentclass{article}%
\usepackage{html}
\usepackage{hyperref}%
\begin{document}
\href{http://www.yahoo.com}{yahoo}
\end{document}

The above can't be processed as is by l2h. To process this with l2h this line

\href{http://www.yahoo.com}{yahoo}

needs to change to one that l2h will process, which is

\htmladdnormallink{yahoo}{http://www.yahoo.com}

So I think all what is needed is to make renewcommand or similar (I am not a Latex expert). So that I would write

\documentclass{article}%
\usepackage{html}
\usepackage{hyperref}%

\begin{htmlonly}
  write something here to make \href{a}{b} below mean \htmladdnormallink{b}{a}
\end{htmlonly}

\begin{document}
\href{http://www.yahoo.com}{yahoo}
\end{document}

I do not know if the above makes sense. or possible. without this, I'd have to find a way to parse the latex file each time and change each \href to \htmladdnormallink (may be I can learn sed or such to do it. But if there is a way to do with Latex macro that will be better.

question is: If the above is possible, what will the correct syntax of this command to add at the top ?

FYI

For completion, this is the final setup so that links work both in SW and l2h

 \documentclass{article}%
 \usepackage{html}  %    for L2H
 \usepackage{hyperref}%  for latex
\begin{document}

\begin{htmlonly}
  \def\href#1#2{\htmladdnormallink{#2}{#1}}  %for L2H only
\end{htmlonly}

\href{http://www.yahoo.com}{yahoo}

\end{document}
share|improve this question

1 Answer 1

up vote 2 down vote accepted

try the following:

\documentclass{article}%
\usepackage{ifpdf}
\usepackage{html}
\usepackage{hyperref}%

\begin{document}
\ifpdf\else
  \def\href#1#2{\htmladdnormallink{#2}{#1}}
\fi

\href{http://www.yahoo.com}{yahoo}
\end{document}

with \ifpdf\else ... \fi you can define code which is only used when running anything else than pdflatex.

share|improve this answer
1  
I am missing the point of the answer actually. How is the above going to change \href to \htmladdnormallink everywhere? I do not want to edit the latex file and manually add different code for html vs. latex each time I add a link. I work in SW all the time, and just run l2h to generate HTML. I wanted a way to do this once, at the top, using a macro, which will refdefine all the href to \htmladdnormallink everywhere only when run by l2h. i.e. I needed a switch type logic added in one place only. Thanks. –  Nasser Jan 6 '13 at 9:15
    
see my edited answer. –  Herbert Jan 6 '13 at 9:19
    
Thanks! Yes, that is what I was looking for. Sorry that I did not understand your earlier answer, as I did not see what to write there. btw, l2h does NOT support \ifpdf and \else and all that. But it was easy to just put the \def command inside \begin{htmlonly} and it worked. Thanks again for your help. –  Nasser Jan 6 '13 at 9:29
    
@Nasser: I know that, but that is not important because it should not be used when running pdflatex and used with latex2html which is true. –  Herbert Jan 6 '13 at 9:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.