change xml info when exporting to LyXHTML

Lorenzo Bertini lorenzobertini97 at gmail.com
Mon Jul 11 02:00:56 UTC 2022


Il 10/07/22 23:50, Steve Litt ha scritto:
> tush via lyx-users said on Sat, 09 Jul 2022 15:54:06 +0000
> 
>> I want to override the default information LyX provides to my document
>> when I export it to xml with Export->LyXHTML
>>
>> At the moment the info inserted to <head> tag is
>>
>> <?xml version="1.0" encoding="UTF-8"?>
>>
>> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0//EN"
>> "http://www.w3.org/Math/DTD/mathml2/xhtml-math11-f.dtd">
>>
>> <html xmlns="http://www.w3.org/1999/xhtml">
>>
>> <head>
>>
>> <meta name="GENERATOR" content="LyX 2.3.6.2" />
>>
>> <meta http-equiv="Content-type" content="text/html;charset=UTF-8" />
>>
>> I am writing my own layout file in which all my customization will be
>> inserted.
>>
>> I want for example to change the first line simply to
>>
>> <!DOCTYPE html>
>>
>> to add
>>
>> <html lang="en">
>>
>> and to include my style sheet:
>>
>> <link href="css/myStyle.css" type="text/css" rel="stylesheet">
>>
>> What changes should I make to the my .layout file?
>>
>> I haven't found this information I am looking for in the Customization
>> manual.

LyX has two (three?) ways of inserting custom stuff in the <head> of a 
LyXHTML document, like for example CSS:

1. if you write your own layout file, or use the convenient "local 
layout" section in the document settings (so you don't have to bother 
with files), LyX will put in the <head> all the relevant CSS.

2. you can put "AddToHTMLPreamble" in a local layout to have custom 
snippets added to the <head>; beware it will be put BEFORE any layout 
generated CSS, so anything hardcoded by the layout will override your 
custom rules; in this case you will have to edit the specific layout (a 
couple lines in the local layout, nothing daunting). This is documented 
in the "Customization" tutorial.

3(?). Some time ago I asked on lyx-devel for a "preamble tab" in 
document settings, but for LyXHTML instead of LaTeX. This would put 
everything inside it AFTER everything in the head so it would have the 
last words on everything. The patch I made is in 
https://www.lyx.org/trac/ticket/12061.

I've been working around LyX quirks when it comes to adding custom stuff 
to LyXHTML for a long time, feel free to ask anything.

> 
> You're speaking my language tush!
> 
> It's been years since I looked at any kind of LyX HTML export, but if
> it's what you're saying now, I might revisit the situation.
> 
> I think what you're asking for is best handled by a post-processor that
> modifies the exported well-formed XML HTML5. Easy and fast with a
> Python program that:
> 
> * Replaces existing doctype with <!doctype HTML>
> 
> * Gets rid of that silly <?xml version="1.0" encoding="UTF-8"?> line.
>    HTML specs say that the UTF-8 line belongs in the <head></head tag
>    pair as "<meta charset="UTF-8"/>". Like you said, the language line
>    belongs in <html lang="en"> or whatever language you want.
> 
> * Replaces the exporter's CSS stylesheet with your own. I don't think
>    you want to mess with your LyX styles in your layout file because you
>    WANT your PDF styles to look very different from your HTML styles.
> 
> This is all accomplished with a very easy to write Python program that
> will postprocess the exported file in a half a second. If the exported
> file is *really* well formed XML, you can check it with my
> xmlchecker.py shown at
> http://troubleshooters.com/web/validating.htm#xmlchecker .
> 
> HTH,
> 
> SteveT
> 
> Steve Litt
> Summer 2022 featured book: Making Mental Models: Advanced Edition
> http://www.troubleshooters.com/mmm

If you think something LyX puts in the preamble is outdated or 
hardcoding too much, feel free to report it on the bug tracker 
https://www.lyx.org/trac/wiki/BugTrackerHome. I'm reporting everything I 
find about LyXHTML but I always feel like I'm the only one using it :).

Lorenzo


More information about the lyx-users mailing list