6

I am generating HTML output for ePub from LaTeX source. But, am having difficulty eliminating the "Chapter " at the start of each chapter. So, wondering if there is an easy way to tell the HTML reader that this is some form of comment so as to not display this in the output?

<span class="titlemark">Chapter&#x00A0;1</span>

Ideally, I'd like to eliminate the <br /> that follows this as well, but not sure that that would be easy.

Notes:

  • The command line tool I am using htlatex which takes a .tex file and produces HTML.
6
  • What program do you use to generate the output? Could you add an automated post-processing step?
    – Anthon
    Commented Oct 14, 2014 at 6:35
  • @Anthon: I am using latexht, but am a bit of newbie with it. For now I have used sed to remove it, but thought perhaps there was a better way. Eventually will have to figure out how to eliminate in the first place. Commented Oct 14, 2014 at 6:39
  • Do you have a link for latexht?
    – Anthon
    Commented Oct 14, 2014 at 7:07
  • @Anthon: Have added a link in the text. Commented Oct 14, 2014 at 8:19
  • The latexht instead of htlatex in your previous comment got me of to the wrong tangent. Google search is not smart enough to see through that (and neither am I).
    – Anthon
    Commented Oct 17, 2014 at 6:48

4 Answers 4

3

If you have an html editor which supports wild card or RegEx search and replace like Adobe Dreamweaver you could delete these out of the source code very quickly. See image below-

enter image description here

Also you can go to RegEx tester sites like these to form the most effective search expression for your needs. http://regex101.com/

1
  • That is sort of what I resorted to but used a perl script to remove it. Did not know about regex101 so thanks for that. Commented Oct 14, 2014 at 20:22
3

You can try to suppress both those tags using CSS in an included .css file (or inserting in the HTML code between <style> and </style>):

span.titlemark, span.titlemark + br {
    display: none;
}

But you would have to test that on all devices to see if their renderers correctly handle it.¹

If you don't want to go into the effort of testing this, it is better to remove both nodes altogether, with appropriate parsing of the input. Using python (2.x) and the BeautifulSoup package², you can do:

import sys
import io
from bs4 import BeautifulSoup

with io.open(sys.argv[1]) as fp:
    soup = BeautifulSoup(fp)

for node in soup.select("span.titlemark"):
    print node.get_text()
    sibling = node.find_next_sibling()
    if sibling and sibling.name == 'br' and not sibling.get_text():
        sibling.extract()
    node.extract()

with io.open(sys.argv[1], 'w') as fp:
    fp.write(unicode(soup))

to get rid of both.³ BeautifulSoup supports several html/xml parser, depending on the type and quality of the output of htlatex, you might need to experiment with the alternatives to get better/faster results.

htlatex is a shell script, so you could make a copy (/usr/local/bin/htlatexstrip) and add calling the python script as a postprocessing step in there.

¹ The X + Y suppresses the sibling <br /> node
² install with pip install beautifulsoup4 or easy_install beautifulsoup4
³ I am sure you can do something like that easily in PERL (or Ruby) as well, I just don't know how

1

If you want them to remain in the source code, but simply hide them in the browser output, you might add the following statement to your style sheets :

.titlemark {
    display:none;
}
0

You could try using CSS to style the titlemark class with "visibility: hidden" or "display:none".

2
  • Can you provide the exact CSS code required. I am not that familiar with CSS, especially for a span class. Commented Oct 14, 2014 at 20:21
  • visibility: hidden would leave the space for the tag in the rendering.
    – Anthon
    Commented Oct 17, 2014 at 6:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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