2

I produced a song book with the songs package, and now I'd like to have an HTML version of the book, with one song for each page, and an optional clickable index.

I tried the usual LaTeX to HTML converters, but the layout (title, subtitle, ...) gets garbled. Pandoc is not respecting styles (every song becomes a long paragraph <p>...</p> and latex2html is outputing a empty pages.

The closest one is tex4ht which is almost perfect, except for the first verse number, which is not in a new line, but in the same line as the title.

Is there a way to interpret the LaTeX source and convert it to some markup language, so I can format it next (with different classes for elements, so I can use CSS, for example)? I tried PlasTeX, but it's very hard to work with.

A minimal example is this:

\documentclass[a4paper,italian,11pt]{article}
\usepackage[lyric,]{songs}
\usepackage[italian]{babel}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\titleprefixword{cdcdcksdjcala}

\begin{document}
\begin{songs}{}
\beginsong{Adeste fideles}
\beginverse
Adeste fideles, l\ae ti triumphantes
venite venite in Bethlehem
Natum videte Regem Angelorum:
\endverse
\beginchorus
Venite adoremus, venite adoremus,
venite adoremus Dominum.
\endchorus
\beginverse
En grege relicto humiles ad cunas
vocati pastores adproperant
Et nos ovanti gradu festinemus.
\endverse
\beginverse
Aeterni Parentis splendorem \ae ternum
velatum sub carne videbimus
Deum infantem pannis involutum. 
\endverse
\endsong

\beginsong{Adoro te devote}
\beginverse
Adóro te devote, latens Déitas,
quæ sub his figuris vere látitas;
tibi se cor meum totum súbicit,
quia, te contemplans totum déficit.
\endverse
\beginverse
Visus, tactus, gustus in te fállitur,
sed áuditu solo tuto créditur.
Credo quidquid dixit Dei fìlius 
nil hoc veritatis verbo vérius.
\endverse
\beginverse
In cruce latebat sola Déitas,
sed hic latet simul et humánitas:
ambo tamen credens atque cònfitens,
peto, quod petivit latro pænitens.
\endverse
\beginverse
Plagas, sicut Thomas, non intúeor:
Deum tamen meum te confiteor:
Fac me tibi semper magis crédere,
in te spem hàbere, te dilígere.
\endverse
\beginverse
O memoriale mortis Dómini,
Panis vivo, vitam præstans hómini:
præsta meæ menti de te vívere,
et te illi semper dulce sàpere.
\endverse
\beginverse
Pie pellicane, Iesu Dómine,
me immundum munda tuo Sànguine,
cuius una stilla salvum fàcere,
totum mundum quit ab omni scélere.
\endverse
\beginverse
Iesu, quem velatum nunc aspício,
oro fiat illud, quod tam sitio:
ut te revelata cernens fácie
visu sim beatus tu\ae{} glóri\ae{}. Amen
\endverse
\endsong

\end{songs}

\end{document}
\bye

And this is a sample output: sample tex4ht output

  • 2
    1. Welcome! 2. Could you provide a minimal document, so that we could try? 3. pandoc is usually the software used to convert TeX to markdown or other formats: did you have a look? – Clément Jan 16 '17 at 22:29
  • 1
    what do you mean by usual convertors?, which ones?, and with what configuration? It is hard to believe that latex2html, tex4ht, latexml, hevea, for example all garbled the layout the same way. – David Carlisle Jan 16 '17 at 23:18
1

You can add custom CSS convert your file with tex4ht, in this case you need to just take a look at the generated code to find out what elements you need to configure:

<span 
class="colorbox" id="colorbox2"><span 
class="ecsx-1728">1</span>    </span>

This is the box with number 1 for your first song. In this case, you need to configure element span with class colorbox. CSS can be introduced using \Css command in the tex4ht configuration file:

\Preamble{xhtml}
\Css{span.colorbox{display:block;max-width:2em;}}
\begin{document}
\EndPreamble

Save this configuration as mycfg.cfg and compile your file using

make4ht -c mycfg.cfg filename.tex

This is the result:

enter image description here

There is still lot to be improved, I will revisit it tomorrow.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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