Opened 21 years ago

Closed 16 years ago

#1440 closed enhancement (fixed)

url inset should produce working hyperlink

Reported by: juergen.leising@… Owned by: poenitz
Priority: high Milestone: 1.6.0
Component: insets Version: 1.3.4
Severity: minor Keywords:
Cc: lasgouttes@…, matej@…, uwestoehr@…, pdenapo@…, ps@…, pelle@…

Description

In document class "article" (not in "docbook" etc.) inserting a url via the
menu item "url" does not produce a "real" hyperlink, but only tt formatted text.
This is not reasonable, because there is already a character style "typewriter".
A better solution is producing clickable links after exporting from latex to
html and pdf. This can be achieved by changing src/insets/seturl.C and
src/LaTeXFeatures.C as follows:

src/insets/seturl.C - line 68: Before:

int InsetUrl::latex(Buffer const *, ostream & os,

bool fragile, bool**free_spc**) const

{

if (!getOptions().empty())

os << getOptions() + ' ';

if (fragile)

os << "
protect";

os << "
url{" << getContents() << '}';
return 0;

}

After:

int InsetUrl::latex(Buffer const *, ostream & os,

bool fragile, bool/*free_spc*/) const

{

if (fragile)

os << "
protect";

if (getOptions().empty())

os << "
htmladdnormallink{
texttt{" << getContents() << "}}{"

<< getContents() << '}';

else

os << "
htmladdnormallink{
texttt{" << getOptions() << "}}{"

<< getContents() << '}';

return 0;

}

src/LaTeXFeatures.C - line 274: Before:

if (isRequired("url") && ! tclass.provides(LyXTextClass::url))

packages << "
IfFileExists{url.sty}{
usepackage{url}}\n"

" {
newcommand{
url}{
texttt}}\n";

src/LaTeXFeatures.C - line 274: After:

if (isRequired("url") && ! tclass.provides(LyXTextClass::url))

packages << "
IfFileExists{url.sty}{
usepackage{url,html}}\n";

commented out: " {
newcommand{
url}{
texttt}}\n";

I changed my own lyx-1.3.3 as mentioned above and now latex2html and pdflatex
both produce clickable links - as everybody would have expected. Maybe using
those html extensions has some drawbacks - I don't know of any, but I'm not a
professional programmer - but for many people this sort of "desktop publishing"
is crucial.

So I recommend considering this proposal.

Bye, bye,

juergen

Change History (27)

comment:1 by levon, 20 years ago

Cc: lasgouttes@… added
Severity: normalenhancement

I understand that there are some problems with doing this (which is why it's
still not done), but I don't know what they are.

comment:2 by Uwe Stöhr, 20 years ago

LyX uses the package url for that. I tested with the actual
url.sty ver 3.0 24-Nov-2003
together with
hyperref 2003/11/30 v6.74m (using pdflatex)
and with the actual tex4ht
and it produces real links.

Seems that the actual url.sty fixes this.
But I didn't test it with latex2html.

comment:3 by juergen.leising@…, 20 years ago

Well, indeed, tex4ht used to produce working links and still
does so. But latex2html does not. In the meantime I upgraded
to

url.sty 2003/11/24 ver 3.0 Verb mode for urls, etc.
hyperref.sty 2003/11/30 v6.74m Hypertext links for LaTeX
hypertex.def 2003/11/30 v6.74m Hyperref driver for HyperTeX specials

and lyx-1.3.4.

This has solved the %-sign-error, AND it has enabled
correct links in a *.pdf produced by pdflatex.

But the upgrade does not lead to clickable links after
a latex2html run.

So I still have to load the package

html.sty 1999/07/19 v1.38 hypertext commands for latex2html (nd, hws, rr

m)
[actually, this is % $Id: html.sty,v 1.39 2001/10/01 22:47:06 RRM Exp $,
but this hasn't been changed accordingly]

and I still have to use \htmladdnormallink to get
clickable links even when I use latex2html.

But anyway - many thanks for your response.

Bye, bye, Juergen.

comment:4 by levon, 20 years ago

In what way is this not a latex2html bug?

comment:5 by levon, 20 years ago

Cc: pdenapo@… added

comment:6 by levon, 20 years ago

* #1475 has been marked as a duplicate of this bug. *

comment:7 by juergen.leising@…, 20 years ago

Oh no, no ping pong, please.

From the point of view of latex2html one can argue:
\htmladdnormallink does work, so it is no latex2html
bug - ask the lyx guys.

And from the point of view of lyx one can argue
as you do: this is a latex2html bug. The blame is
on them.

So pretty much like our local authorities: It's not
our business, ask the other ones. And those, of
course, say the same thing ...

One thing is for sure: the default conversion settings
do not lead to clickable links. And THIS should be
the only point that really matters.

bye, Juergen

comment:8 by levon, 20 years ago

I at least want a rationale from the latex2html people as to why \url shouldn't
be rendered as desired.

comment:9 by lasgouttes, 20 years ago

The following from the latex2html list will probably help:
http://www.tug.org/pipermail/latex2html/2004-March/002678.html

It is maybe time to reconsider our strange handling of url.sty and assume
that all latex installations do have url.sty installed. This was not
true back in 1999, but things have changed. This would of course
not fix all of our problems, but may be a good first step.

The second issue is to see how we can use the new flavor support in OutputParams
to use an html flavor. Unfortunately, it seems that the various latex->html
converters never managed to agree to a common subset functionality.

Something that may be usable though in the html export case is the support
for hyperref commands like \href.

comment:10 by levon, 20 years ago

Wow. That's just deeply backwards. I know the presentation vs. content layers
are screwed in LaTeX, but this is very silly.

But, we must do what we must do I suppose.

comment:11 by juergen.leising@…, 20 years ago

Version: 1.3.21.3.4

\url doesn't get rendered correctly, presumably because of this:

\IfFileExists{url.sty}{\usepackage{url}}

{\newcommand{\url}{\texttt}}

Simply commenting out this whole line and additionally
using the html.sty package does lead to clickable
links both in latex2html and pdftex.

But I'm going to ask the latex2html mailing list in the
next days.

But the results are not good enough, yet, as you normally
want different text as the HREF value and the content
of the A element in HTML. And this can easily be
achieved by \htmladdnormallink.

bye, Juergen.

comment:12 by juergen.leising@…, 20 years ago

Hello to all,

here are the 3 replies I got from the latex2html
mailing list:

From: Ross Moore <ross@…>

On 22/04/2004, at 6:52 AM, Juergen Leising wrote:

Hello,

using lyx-1.3.4 I have some difficulties with producing
clickable links, like some others here on the list.

First I add

\usepackage{html}

This leads to clickable links after converting the document

by tex4ht or by pdftex, but not by latex2html.

That is surprising, since the html.sty package is written
specially for latex2html .
Furthermore, with html.sty and LaTeX2HTML, there is
no need to load url.sty or do anything else to get
active hyperlinks --- they should just work.
However ...

... I think LyX adds extra TeX tests into the preamble,

and it is these that cause the problems with LaTeX2HTML.
(I don't use LyX myself, so do not know for sure, but have

seen reports of this kind previously --- besides, it may
depend upon version or your specific content.)

All you need to do is surround this extra, irrelevant
(at least to LaTeX2HTML) preamble stuff with comments:

%begin{latexonly}
...
... coding with \if or \ifx tests, or somesuch
...
%end{latexonly}

Now LaTeX2HTML will recognise that this is stuff
that isn't needed, and could even be damaging,
so just ignores it completely.
For any other (La)TeX processor, these are just comments.

(...)

From: Philipp Murkowsky <murkowsky@…>

Hello Juergen

Juergen Leising wrote:

First I add

\usepackage{html}

This leads to clickable links after converting the document
by tex4ht or by pdftex, but not by latex2html.

I don't use Lyx any more but in my LaTeX documents I use

\usepackage[obeyspaces,spaces,hyphens]{url}
\usepackage{hyperref}

(in this order!) which gives me proper hyperlinks in HTML and PDF
output. For details about the options of the url-Package see the
comments in the file url.sty.

HTH, Philipp

From: "Jean-Pierre.Chretien" <Jean-Pierre.Chretien@…>

(...)

So my question is: why does latex2html not render \url
to a proper hyperlink, whereas the other converters (tex4ht, pdftex) do
produce working links?

The original lyx code:
See
\begin_inset LatexCommand \url[my_link]{http://www.lyx.org}

THe latex code produced by exporting to latex:
See my_link \url{http://www.lyx.org}

So anyway the « Name » field in the url LyX inset will not be the anchor

ERT is needed to produce the good l2h result:
\begin_inset ERT
status Open
\layout Standard

\backslash
htmladdnormallink{my_link}{http://www.lyx.org}
\end_inset

Works fine.

Liable to prefiltering in a wrapper script calling l2h if you want to avoid ERT.
As the latex file does not feeds back the anme field, I don't see another way.

(...)

comment:13 by juergen.leising@…, 20 years ago

now, taking those answers into account, I would say, the line

\IfFileExists{url.sty}{\usepackage{url}}

{\newcommand{\url}{\texttt}

in

lyx-1.3.4/src/LaTeXFeatures.C

definitely is a bug. Instead it should read

\IfFileExists{url.sty}{\usepackage[obeyspaces,spaces,hyphens]{url}}

{\urlstyle{tt}}

I've already tried this, and it does lead to clickable links
even when I use latex2html, provided that html.sty has been loaded before.
The only drawback is, that the difference between the actual url
and the name you want to use for that url doesn't get reflected in the
usual way.

But I myself prefer getting elements like

<a href="http://www.example.com">any link</a>

so there seems to be no other way than using

\htmladdnormallink{any link}{http://www.example.com/}

instead of \url.

\usepackage{html} and \htmladdnormallink can be inserted
by the user in Layout-Document-Preamble resp. by ERT.
But the \newcommand line has to be modified in the source code.

Bye, bye, Juergen

comment:14 by lasgouttes, 20 years ago

In 1.4.0cvs, it is possible to generate different code depending on what
kind of latex we want (pdflatex, latex currently). We could create a new
latex-for-html flavor that would do the following:

  • use \usepackage{hypertex} with appropriate options in header. The idea is that I want to avoid using html.sty which is latex2html-specific. Will latex2html recognize hyperref without loading html.sty? What would be the 'right' hyperref options?
  • output \htmladdnormallink instead of \url as you suggest. Do we really need to output in \tt? It does not seem nice to me in HTML documents.

Doing the same in 1.3.x would be more difficult.

I can try to do it, but my time is very limited, so I cannot promise
anything.
If you are willing to try your hand on this, I will be here to help you ;)

comment:15 by juergen.leising@…, 20 years ago

I've written:

\IfFileExists{url.sty}{\usepackage[obeyspaces,spaces,hyphens]{url}}

{\urlstyle{tt}}

This is buggy, as well. Sorry. Second service:

\IfFileExists{url.sty}{\usepackage[obeyspaces,spaces,hyphens]{url}

\urlstyle{tt}}{}

The syntax is

\IfFileExists{<file>}{<yes>}{<no>}

So the original lyx-1.3.4 code is correct, as far as latex is concerned -
only latex2html seems to have problems with the \newcommand line.

Bye, Juergen

comment:16 by juergen.leising@…, 20 years ago

We could create a new
latex-for-html flavor that would do the following:

  • use \usepackage{hypertex} with appropriate options in header. The idea is that I want to avoid using html.sty which is latex2html-specific. Will latex2html recognize hyperref without loading html.sty?

yes and no. latex2html will not recognize \htmladdnormallink without
html.sty, although \htmladdnormallink is already defined by hyperref.sty.
But it will accept \url regardless of any special options to \usepackage{hyperref}.

What would be the
'right' hyperref options?

good question - I don't know. I'm not too familiar with hyperref.
There is an option

[latex2html]{hyperref}

but I haven't seen any substantial effect of this option, so far.
hyperref.sty seems to me to be the main interface to pdf, but not to html.
On the other hand, there are several other converters I haven't tried so far:

http://www.cse.ohio-state.edu/~gurari/TeX4ht/mn.html#QQ1-1-79

So following a more general approach does make sense.

  • output \htmladdnormallink instead of \url as you suggest. Do we really need to output in \tt? It does not seem nice to me in HTML documents.

no, we don't need \tt at all. But latex2html seems to ignore all trials to
avoid \tt formatting: Neither

\IfFileExists{url.sty}{\usepackage[obeyspaces,spaces,hyphens]{url}

\urlstyle{rm}}{}

nor

\IfFileExists{url.sty}{\usepackage[obeyspaces,spaces,hyphens]{url}

{}

avoids \texttt in the html output. The dvi, however, is correct.
Using \htmladdnormallink even makes latex2html avoid \tt.

Bye, Juergen

comment:17 by matej@…, 20 years ago

Cc: matej@… added

comment:18 by Georg Baum, 18 years ago

Keywords: fileformat added

comment:19 by Uwe Stöhr, 18 years ago

Cc: uwestoehr@… added

comment:20 by Juergen Spitzmueller, 18 years ago

Cc: pelle@… added

comment:21 by Juergen Spitzmueller, 18 years ago

* #2639 has been marked as a duplicate of this bug. *

comment:22 by Uwe Stöhr, 18 years ago

dependson: 2268

comment:23 by Richard Heck, 17 years ago

blocked: 3482

comment:24 by ps@…, 17 years ago

Cc: ps@… added

comment:25 by Uwe Stöhr, 17 years ago

Keywords: fixedintrunk added
Milestone: 1.6.0

comment:26 by Juergen Spitzmueller, 16 years ago

Keywords: fixedintrunk removed
Resolution: fixed
Status: newclosed

LyX 1.6.0 is released.

comment:27 by Richard Heck, 10 years ago

Keywords: fileformat removed

Don't need this keyword with closed bugs.

Note: See TracTickets for help on using tickets.