# TeX4ht fails to insert </div> at \end{center} with standalone class

mwe.tex:

%%%%%%% Example 1. that works correctly %%%%%%%%%%%%%%%%%%%%
%\documentclass{article}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%% Example 2. fails to insert </div> at \end{center} %%
\documentclass[varwidth=160mm]{standalone}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{document}
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac,adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuerid, vulputate a, magna.

\begin{center}
Hello everyone!
\end{center}

Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."

Bye!
\end{document}


mwe.cfg:

\Preamble{xhtml,html5}
\begin{document}
\EndPreamble


\$ make4ht -u -c mwe.cfg mwe.tex

With standalone produces mwe.html: (screenshot from browser)

Everything from "Hello everyone!" onwards is centered. This is due to missing </div> that should close <div class="center"> in the compiled html. Compiling with \documentclass{article} produces expected result: (screenshot from browser)

I have two questions:

1. How to fix this? Should I file a bug report?

2. What is recommended documentclass when compiling to html with TeX4ht (make4ht more specifically) and would it be possible to ignore documentclass in tex source file and use another class instead? Mass editing of my ~1000 standalone snippets that are used also for other purposes isn't an option unfortunately.

It seems that standalone somehow redefines the way environments are handled and it causes that code which inserts HTML tags at the end of an environment isn't executed. It happens not only to center, but to any other environment, such as itemize, etc.

I haven't found the cause of this trouble, but it can be fixed with simple hack:

% standalone.4ht
\def\sa@cls@afterbegindocument{}
\def\sa@cls@beforeenddocument{}

\Hinput{standalone}

\endinput


The two redefined macros originally executes standalone redefinitions, so it is possible that you will find more issues on your real-world examples. It it works, I will update the source code of tex4ht.

Regarding your second question, we hope that all document classes works, but standard article or book classes have best support.

This is the result:

• The hack indeed fixes the div-tag problem. The document also compiles ok but the hack changes things like indentation and paragraph breaks which is undesired. I think I split the second question into its own thread. – Jarno_C-137 Sep 3 '17 at 12:52
• @Jarno_C-137 OK, it will be indeed better to post detailed example of new issues as separate question. – michal.h21 Sep 3 '17 at 12:57