Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for \addvspace #130

Open
claell opened this issue Apr 26, 2024 · 3 comments
Open

Add support for \addvspace #130

claell opened this issue Apr 26, 2024 · 3 comments

Comments

@claell
Copy link

claell commented Apr 26, 2024

Continuation from #125 to not make that issue too long and keep discussions on different topics easier to follow.

I think in HTML, this CSS definition should suppress additional spaces after multiple \epubvspace commands that immediately follows each other:

\Css{.vspace + .vspace{height:0;margin:0;}}

Originally posted by @michal-h21 in #125 (comment)

Thanks! I had a similar idea after thinking about it again.

Unfortunately, after testing, it doesn't work as expected.
I also created a MWE, as this seems to be needed. 🙂

LaTeX:

\documentclass{article}
\usepackage{addvspacetest}
\usepackage{lipsum}

\begin{document}

\section{hello}
\lipsum[1-2]

\epubaddvspace{2em}
third: \lipsum[3]

\epubaddvspace{2em}
\epubaddvspace{2em}
fourth: \lipsum[4]
\end{document}

Style:

\ProvidesPackage{addvspacetest}

\newcommand\epubaddvspace[1]{\addvspace{#1}}

.4ht file:

\def\pt:to:em#1{\strip@pt\dimexpr#1/\f@size em}
\renewcommand\epubaddvspace[1]{\edef\:vspacesize{\pt:to:em{#1}}\a:epubaddvspace}
\NewConfigure{epubaddvspace}{1}
\Configure{epubaddvspace}{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="addvspace" style="height:\:vspacesize">}\:nbsp\HCode{</div>}}
\Css{.addvspace + p{margin-top:0pt;}}
\Css{p + .addvspace{margin-top:0pt;}}
\Css{.addvspace + .addvspace{height:0;margin:0;}}

Command to invoke tex4ebook

tex4ebook -f epub3 test.tex p-indent

Result PDF:
grafik

Result EPUB:
grafik

Also, as general note: This won't work as \addvspace, which would use the biggest space, and not the first one (as this example does IMHO). For me, that is not a problem, as subsequent spaces would have the same height (at least currently). But just as a note.

@michal-h21
Copy link
Owner

I've realized that there is a bug in \Configure{epubaddvspace}. It didn't start a paragraph. Here is a fixed version:

\def\pt:to:em#1{\strip@pt\dimexpr#1/\f@size em}
\renewcommand\epubaddvspace[1]{\edef\:vspacesize{\pt:to:em{#1}}\a:epubaddvspace}
\NewConfigure{epubaddvspace}{1}
\Configure{epubaddvspace}{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="addvspace" style="height:\:vspacesize">}\HCode{</div>}\par}
\Css{.addvspace + p{margin-top:0pt;}}
\Css{p + .addvspace{margin-top:0pt;}}
\Css{.addvspace + .addvspace{height:0;margin:0;}}

Regarding the issue with multiple spaces, I forgot that we set explicitly the height using inline styles. This overwrites anything that is written in the CSS file. In this case, I think it is best to use a Lua build file that will remove extra spaces:

local domfilter = require "make4ht-domfilter"

local process = domfilter {
  function(dom)
    for _, vspace in ipairs(dom:query_selector(".addvspace + .addvspace")) do
      vspace:remove_node()
    end
    return dom
  end
}

Make:match("html$", process)

Compile using

 $ tex4ebook -e build.lua -f epub3 test.tex p-indent

@claell
Copy link
Author

claell commented Apr 26, 2024

What is the effect of (not) starting a paragraph in the command?

I also noticed that you removed the non-breaking space. I already wondered whether it should be there, before.

With the additional Lua build file, it works for me, now!

@michal-h21
Copy link
Owner

It caused the build file to work incorrectly, because it detected two vspaces as following each other even if there was a text between them. Paragraph element is needed to prevent that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants