Closely Related: Changing paragraph begin/end commands

Is there a LaTeX "hook" for automatically wrapping paragraphs in boxes, or preferably XML tags?

I would like to load the outputted file into an XML parser, but with each paragraph as a separate row.

Example Input File:


    Hello World.

    Hello Again.

Example of Simple Outputted XML file:

    <Paragraph>Hello World.</Paragraph>
    <Paragraph>Hello Again.</Paragraph>

Actual Use Case:

Just trying to export a book chapter in XML format for input into the Sigil epub editor.

  • 1
    easiest is to use tex4ht (htlatex) and output xml syntax html. or latexml, but you have already tagged your question with both of those systems, so it isn't clear what else you are asking? Commented May 20, 2020 at 7:21
  • @DavidCarlisle - I have been researching them both, but haven't figured out the actual syntax to do it using those systems. But, I am also wondering if there isn't just a low level "TeX/LaTeX" "hook" that will allow me to do it without tex4ht, (if that is even possible). Like perhaps, \everypar and an \everyendpar command ... (which I can't find.) Commented May 20, 2020 at 7:25
  • Do you expect XMLTeX???
    – MadyYuvi
    Commented May 20, 2020 at 7:46
  • @elikakohen just let them output html then transform the <p> to <Paragraph> using xml transformation or a simple text edit. (I am surprised there an epup editor that doesn't accept html input?) Commented May 20, 2020 at 7:47
  • @MadyYuvi - I updated the MWE with the kind of answer I thought I was looking for. But, I am not trying to read XML, just trying to write it. Commented May 20, 2020 at 7:54

2 Answers 2


I am not sure what you actually want to do. If you want to create an Epub file, you can convert your LaTeX source to Epub using tex4ebook. Run the following command in terminal:

 tex4ebook filename.tex

If you really want to create custom XML syntax, then it is much more difficult task. You would need to create configurations for hundreds of commands, it isn't just paragraphs.

Anyway to answer the question as it is, you can configure tags for paragraphs using the following configuration file:


Compile your file using:

make4ht -c config.cfg filename.tex

This is the result:

<!DOCTYPE html> 
<html lang='en-US' xml:lang='en-US'> 
<head> <title></title> 
<meta charset='utf-8' /> 
<meta content='TeX4ht (https://tug.org/tex4ht/)' name='generator' /> 
<meta content='width=device-width,initial-scale=1' name='viewport' /> 
<link type='text/css' rel='stylesheet' href='sample.css' /> 
<meta content='sample.tex' name='src' /> 
<paragraph>Hello World.
</paragraph><paragraph>    Hello Again. </paragraph> 

As you can see, there is lot of HTML tags. Much more \Configure commands would be necessary to change that to a custom XML scheme.

  • Thanks! That is exactly what I am looking for. Commented May 20, 2020 at 8:55

As the OP, this is an example answer of what I am trying to do.

I am hoping for other, cleaner, ways of doing this.

\documentclass[openany, oneside, 12pt]{minimal}
    \everypar={\textless Paragraph\textgreater}%
    Hello World.

    Hello Again.

  • you want to typeset the xml syntax?? why? I assumed in the comments under your question that you wanted to output the document as xml (which was why I suggested lthtml (which has an option for epub output) your TagParagraphs and StopTaggingPargraps commands add space as you have omitted % from ends of lines Commented May 20, 2020 at 8:43
  • the \makeat.. commands are doing nothing here as they do nothing useful inside a command definition (they should be outside it) and there are no @ in your code anyway) Commented May 20, 2020 at 8:45
  • you are adding a space after the .% put a % after that as well (the standard definition of \par removes that space with \unskip but you redefined \par. But I still don't see why you want to typeset xml markup into the pdf output, how does that help you map to epub? Commented May 20, 2020 at 10:02
  • after your edit you are still missing % in your command definitions, both of your definitions start by adding a space. Commented May 20, 2020 at 11:00
  • @DavidCarlisle - Thank you again, it was the missing \unskip. Commented May 20, 2020 at 18:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .