1

problem

When a paragraph contains a block quote, xelatex formats the portion after the quote, correctly, without an indent. Tex4ht, however, treats it as a new, and therefore indented, paragraph.

MWE

main.tex:

%!TEX TS-program = xelatex
%!TEX encoding = UTF-8 Unicode

% Normal:
\documentclass[12pt,letterpaper,oldfontcommands,article]{memoir}

\begin{document}

\section{a section}

First paragraph.

Second paragraph. This one is indented. That is how it should be.
\begin{quote}
This is a block quote.
\end{quote}
This continuation of the paragraph after the block quote should not be indented. With xelatex it is not, but with tex4ht it is.

When a block quote comes at the end of a paragraph, by contrast, the new paragraph should be indented.
\begin{quote}
Here is another block quote.
\end{quote}

This is a new paragraph, so it \emph{should} be indented, to make clear that it is a new paragraph rather than the continuation of the paragraph containing the block quote.
\end{document}

compiling command:

make4ht -ux -a debug -f odt main.tex

xelatex output (correct):

enter image description here

tex4ht output (incorrect):

enter image description here

The key paragraph to look at is the "second paragraph."

question

How can I make tex4ht produce the correct output?

1 Answer 1

1

Try this configuration file:

\Preamble{xhtml}
\catcode`\:=11
\ConfigureEnv{quote}
   {\ifvmode \IgnorePar\fi \EndP
\ifnum \BegEnd:D=0
   \gHAdvance\BegEnd:N by 1
\HCode{<text:section
        text:style-name="begin-end-env"
        text:name="begin-end-env-\BegEnd:N"
       >%
       <text:p text:style-name="begin-env-p" ></text:p>}%
%
\else
   \gHAdvance\BegEnd:N by 1
\hbox{\HCode{<text:p><draw:frame
                draw:name="begin-end-env-\BegEnd:N"
                 draw:style-name="env-frame"
                 text:anchor-type="as-char"
%                 fo:min-width="0.14in"
                 svg:width="90\%"
                 draw:z-index="0"
       >
       <draw:text-box
%           fo:min-height="0.14in"
       >}}%
%
\fi
\gHAdvance\BegEnd:D by 1
}
   {\gHAdvance\BegEnd:D by -1
\ifvmode \IgnorePar\fi\EndP
\ifnum \BegEnd:D=0
   \HCode{<text:p text:style-name="end-env-p" ></text:p></text:section>}%
%
\else
   \hbox{\HCode{</draw:text-box>
</draw:frame></text:p> }}%
%
\fi
\par\noindent}
   {\EndP \ifvmode \IgnorePar\fi
    \bgroup \Configure{HtmlPar}
   {\EndP \HCode{<!--l. \the\inputlineno-->%
%
                 <text:p text:style-name="quote\if@rl-rtl\fi
"
                         >}}
   {\EndP \HCode{<!--l. \the\inputlineno-->%
%
                 <text:p text:style-name="quote\if@rl-rtl\fi
"
                          >}}
   {\HCode{</text:p>}}
   {\HCode{</text:p>}}%
%
   }
   {\IgnorePar\EndP \egroup \ShowPar \ShowIndent}
\catcode`\:=12
\begin{document}
\EndPreamble

It is a copy of configuration for quotation from TeX4ht sources. Only change is that it uses

par\noindent 

command at end of the third argument, to suppress indentation.

This is the result:

enter image description here

Edit:

To remove an empty paragraph before indented paragraph, use this build file, build.lua:

local domfilter = require "make4ht-domfilter"


local process = domfilter {
  -- this function removes empty paragraphs after quote environment
  function(dom)
    -- test if the previous paragraph style was "quote"
    local ignored_styles = {
      ["end-env-p"] = true
    }
    local prev_style 
    for _, par in ipairs(dom:query_selector("text|p")) do
      local style = par:get_attribute("text:style-name")
      -- if the previous paragraph was quote and the current paragraph is empty,
      -- then remove it
      if prev_style == "quote" then
        if not ignored_styles[style] 
           and par:get_text():gsub("%s*", "") == "" -- test if paragraph is empty
        then
          par:remove_node()
        end
      end
      -- ignore the end-env-p style, which is inserted at the end of the quote environment
      if not ignored_styles[style] then
        prev_style = style
      end
    end

    
    return dom
  end
}

-- register the filter to process the document
Make:match("4oo", process)

Compile using:

make4ht -c config.cfg -f odt -e build.lua filename.tex
16
  • This has fixed the problem I raised, but it looks from your screenshot that there is now no way to make the paragraph after a block quote indented. (See the last two lines of the example, which should be indented -- and are in the xelatex output.) Dec 29, 2021 at 1:19
  • @AlexRoberts try the updated version. The downside is that it inserts blank paragraph before indented paragraph. I think this cannot be solved on the TeX level, but the empty paragraph can be removed using Lua filter.
    – michal.h21
    Dec 29, 2021 at 14:56
  • Thank you for the update. Are you sure that tex4ht can't manage it? Xelatex does it without a problem; perhaps the same criterion for indentation could be carried over to tex4ht? That is, whenever xelatex would indent the paragraph, set the paragraph style in ODT to indented; and whenever xelatex would not indent, use the non-indented ODT paragraph style. Dec 29, 2021 at 23:10
  • 1
    @AlexRoberts yes, because paragraph handling is quite difficult in the ODT output. You must do various tricks to create correct XML structure, so it doesn't matter how LaTeX itself handles it :/
    – michal.h21
    Dec 30, 2021 at 19:08
  • I see. Well, in any case, it is certainly much easier to delete extra paragraph gaps than to go back and figure out which ones I wanted to keep indented as I was doing before. So thank you again! Jan 1, 2022 at 21:55

You must log in to answer this question.

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