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

Support for \vspace #125

Open
claell opened this issue Apr 21, 2024 · 20 comments
Open

Support for \vspace #125

claell opened this issue Apr 21, 2024 · 20 comments

Comments

@claell
Copy link

claell commented Apr 21, 2024

Recently, I discovered, that currently, there doesn't seem to be support for the \vspace command.

I assume this is on purpose, similar to #100.

However, especially with the option p-indent, that causes visual problems when one wants to visually separate some paragraphs from others (also see #122 for the similar issue that is about horizontal margins).

I hope, some good solution for this can be found.

@michal-h21
Copy link
Owner

I think it is better to use custom commands in this case. \vspace is used internally by many commands, so it could lead to unexpected results if you always insert vertical space for it. See this answer for some examples.

@claell
Copy link
Author

claell commented Apr 21, 2024

Yes, I understand and agree. Ideally, something like in #117 could be provided to ensure robustness of code, maintainability and ease of use.

@claell
Copy link
Author

claell commented Apr 21, 2024

Based on the given material, I have (theoretically, untested) came up with something like:

LaTeX file/style:

\newcommand\epubvspace[1]{\vspace{#1}}

Configuration file for tex4ebook:

\renewcommand\epubvspace[1]{\a:epubvspace}
\NewConfigure{epubvspace}{1}
\Configure{epubvspace}{\ifvmode\HCode{<span class="vspace">}\:nbsp\HCode{</span>}\fi}
\Css{.vspace{height:#1;margin:0;}}

Is that sensible (does it work, and other improvement suggestions)?

@michal-h21
Copy link
Owner

For this LaTeX package, this .4ht file should work:

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

It saves the amount specified for the \epubvspace command into \:vspacesize command, so it can be reused in the configuration. It also converts any specified dimension to em units. \Css commands removes default vertical spaces between div and p, so only the specified amount is used.

@claell
Copy link
Author

claell commented Apr 23, 2024

Nice, perfect. Many thanks!

Right now, I am not sure, if I am doing things right. I have included the command creation in a LaTeX style that gets loaded in the main LaTeX document.

And I also created epubvspace.4ht and placed it next to the main folder with the LaTeX file where tex4ebook gets called.

Unfortunately, it doesn't seem to have an effect. Do I need to place the .4ht file somewhere else?

@michal-h21
Copy link
Owner

Is the main style named epubvspace.sty? If not, you may need to rename the epubvspace.4ht to the same basename. If they are same, can you find in the .log file that epubvspace.4ht is loaded?

@claell
Copy link
Author

claell commented Apr 23, 2024

Ah, okay, didn't know that. The main style is at a sub folder (possibly, that might also cause further conflicts) and is just named book.sty.

So I'll try with book.4ht for now.

@claell
Copy link
Author

claell commented Apr 23, 2024

Interesting. Now, the spacing seems to work, at least. But it broke many other things, like the TOC, etc.

@claell
Copy link
Author

claell commented Apr 23, 2024

I assume, book.4ht conflicts with another "package" that has the same name?

@michal-h21
Copy link
Owner

Well, it clashes with book.cls. I would suggest to rename the package to something different, for example mybook.sty and mybook.4ht. This should prevent errors.

@claell
Copy link
Author

claell commented Apr 24, 2024

Ah, yes, makes sense. I have set it up in this way in many projects, but probably, it is a good thing to rename it, in general. Will test again and report back.

@claell
Copy link
Author

claell commented Apr 24, 2024

Mh, I renamed as you suggested. The weird thing is that now, the \epubvspace command doesn't get applied in the EPUB.

I'll try to check whether I can fix that by moving the location of mybook.sty (which was in a subfolder, previously) or moving mybook.4ht to that subfolder.

@michal-h21
Copy link
Owner

In this case, you should put the .4ht file to the same directory as your .sty file.

@claell
Copy link
Author

claell commented Apr 24, 2024

Okay, so moving both to the same subfolder didn't work (possibly to a flawed way of me integrating that style), but moving mybook.sty to the main folder worked. That is at least some good news :)

Moving forward, I am hoping to get the command integrated by default (like in #117).

Also, as I am currently not sure about integration of .4ht files in different locations, I opened #128 to easily find that information later.

@claell
Copy link
Author

claell commented Apr 24, 2024

So for the flawed integration of that style:

Before, I did it like:

\usepackage{./subfolder/mybook}

and in the style:

\ProvidesPackage{mybook}

which always gave the warning

LaTeX: You have requested package `./subfolder/mybook',
               but the package provides `mybook'.

So I fixed that with changing the style to

\ProvidesPackage{./subfolder/mybook}

Unfortunately, that still doesn't make the mybook.4ht get used when it is next to mybook.sty inside of subfolder.

@michal-h21
Copy link
Owner

Try

\usepackage{subfolder/mybook}

The leading ./ seems to be causing trouble.

@claell
Copy link
Author

claell commented Apr 25, 2024

Thanks, that works!

@claell
Copy link
Author

claell commented Apr 25, 2024

After checking back with my PDF, I noticed, that sometimes, vspaces follow each other, in which case, I don't want them to add up. So actually, I need to use \addvspace for that (https://tex.stackexchange.com/questions/398590/ignore-vertical-spaces-that-follow-one-another).

Similarly, support for \epubaddvspace would be great!

I have been experimenting a bit with margins and other options, but didn't get a working result, yet. I think, collapsible margins might be a way to achieve it.

@michal-h21
Copy link
Owner

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;}}

@claell
Copy link
Author

claell commented Apr 26, 2024

Thanks! As that topic seems to be also a bit more expanding, I created a follow-up issue: #130.

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