On 04/09/2025 22:58, Max Nikulin wrote:

Perhaps Org still should gracefully handle a case of early draft of long document with outline and nothing more.

+++ b/lisp/ox-latex.el
@@ -2428,7 +2428,7 @@ (defun org-latex-headline (headline contents info)
              ;; Maybe end local TOC (see `org-latex-keyword').
              (contents
               (concat
-               contents
+               (or contents "\\leavevmode")
                (let ((case-fold-search t)

"\\penalty0" may be safer (perhaps with additional "\\relax " or newline for a case that next portion of text will be started from a number without any space). I was not aware that penalties are not combined by TeX, any is considered as a break point. There are various tricks like \vfil\penalty100\vfilneg to allow variation of page height.

Maybe e.g. 100 should be used instead of zero to make less probable page break between section and subsection titles. (Carefully prepared text likely will have at least a paragraph before next level header. Anyway nobody expects that early drafts are carefully formatted.)

There are should be a user option to disable this workaround and probably an "#+options:" keyword. It should be carefully tested with inline headings (\paragraph{...} and similar).

I still believe that it is a LaTeX issue. I see why it is not supported, but any workaround may be fragile. I am really surprised that TeX does not generate apparent warning due to a page of enormous height.

On 07/09/2025 05:19, David Masterson wrote:
I should run this test case on other export engines to see how they
handle it...

As to headings of arbitrary depth, HTML has <h1>...<h6> elements with <h1> for page title, so just 5 levels of sections. Sometimes even <h4> is hardly distinguishable from <h3>, especially there no other headings are visible due to long text between. It is better to not abuse nested levels of headings.

Reply via email to