michal-h21 / tex4ebook

Converter from LaTeX to ebook formats (epub, mobi). Using tex4ht and texlua scripts.
311 stars 32 forks source link

Respect right margins (like from `changepage`'s `adjustwidth` environment) #122

Closed claell closed 6 months ago

claell commented 11 months ago

I noticed that the right margins set with adjustwidth don't seem to get respected.

Also, are the left margins constant or is the actual margin value taken into consideration? It doesn't seem to have an effect for me.

MWE:

\documentclass{book}
\usepackage{lipsum}
\usepackage{changepage}

\begin{document}

\lipsum[1]
\begin{adjustwidth}{5em}{5em}
    \lipsum[1]
\end{adjustwidth}
\lipsum[1]

\end{document}

PDF:

grafik

EPUP in Calibre Viewer:

grafik

michal-h21 commented 11 months ago

The Changepage package is not supported yet, but it is not too hard to add support for this. Try this configuration file, changepage.4ht:

\NewConfigure{adjustwidth}{2}

\def\:tempa#1#2{%
\def\adjustwidth:left{#1}%
\def\adjustwidth:right{#2}%
\a:adjustwidth%
}
\HLet\adjustwidth\:tempa
\expandafter\HLet\csname adjustwidth*\endcsname\:tempa

\def\:tempa{\b:adjustwidth}
\HLet\endadjustwidth\:tempa
\expandafter\HLet\csname endadjustwidth*\endcsname\:tempa
\def\pt:to:em#1{\strip@pt\dimexpr#1/\f@size em}

\Configure{adjustwidth}{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="ajdustwidth" style="margin-left:\pt:to:em\adjustwidth:left;margin-right:\pt:to:em\adjustwidth:right;">}\par\ShowPar}{\ifvmode\IgnorePar\fi\EndP\HCode{</div>}}

\Hinput{changepage}
\endinput
claell commented 11 months ago

Thanks again! I'll need to look into using such config files!

As a side note: Might it be sensible to print warnings in case unsupported packages are found? That way, the user knows that something isn't (or might not be) working as expected.

michal-h21 commented 11 months ago

As a side note: Might it be sensible to print warnings in case unsupported packages are found? That way, the user knows that something isn't (or might not be) working as expected.

The problem is that some packages may not work properly even if they are supported. Something can break in every package update. So such warning could be misleading :)

claell commented 11 months ago

Mh, I partly understand where you are coming from (people thinking that everything is fine as long as there is no warning), but think no warning at all is worse. One can probably structure the warning in a way that it also tells that simply changing things until the warning is gone is no guarantee that now everything is perfect with the generated document.

michal-h21 commented 11 months ago

OK, I've added this feature to make4ht, but only as an info message, so you will need to use -a debug or -a info options to print them.

On this example I get:

$ make4th -m draft -a info sample.tex
[INFO]    mkparams: Output dir: 
[INFO]    mkparams: Compiler: latex
[INFO]    mkparams: Latex options: -jobname='sample'  
[INFO]    mkparams: tex4ht.sty: xhtml,,charset=utf-8
[INFO]    mkparams: tex4ht:  -cmozhtf -utf8
[INFO]    mkparams: build_file: sample.mk4
[INFO]    mkparams: Output format: html5
[STATUS]  make4ht: Conversion started
[STATUS]  make4ht: Input file: sample.tex
[INFO]    mkutils: Load extension       common_domfilters
[INFO]    mkutils: Cannot open config file      sample.mk4
[INFO]    make4ht-lib: setting param correct_exit
[INFO]    make4ht-lib: Adding:  ext     dvi
[INFO]    htlatex: LaTeX call: latex --interaction=batchmode  -jobname='sample'   '\makeatletter\def\HCode{\futurelet\HCode\HChar}\def\HChar{\ifx"\HCode\def\HCode"##1"{\Link##1}\expandafter\HCode\else\expandafter\Link\fi}\def\Link#1.a.b.c.{\let\HCode\documentstyle\def\documentstyle{\let\documentstyle\HCode\expandafter\def\csname tex4ht\endcsname{#1,html}\def\HCode####1{\documentstyle[tex4ht,}\@ifnextchar[{\HCode}{\documentstyle[tex4ht]}}\RequirePackage[#1,html]{tex4ht}}\makeatother\HCode xhtml,,charset=utf-8,html5.a.b.c.\input "\detokenize{sample.tex}"' > /dev/null 2>&1
[INFO]    htlatex: Unsupported file: expl3.sty
[INFO]    htlatex: Unsupported file: l3keys2e.sty
[INFO]    htlatex: Unsupported file: lipsum.sty
[INFO]    htlatex: Unsupported file: changepage.sty
[INFO]    mkutils:  xhtml,charset=utf-8,html5,html
[INFO]    mkutils: executing: tex4ht  -cmozhtf -utf8 "sample.dvi"
[INFO]    mkutils: executing: t4ht  "sample.dvi"
[INFO]    mkutils: Parse LG
[INFO]    make4ht-lib: parse_lg process file: sample.html
[INFO]    make4ht-lib: parse_lg process file: sample.html
[INFO]    make4ht: No output directory
[INFO]    make4ht-lib: parse_lg process file: sample.css
[INFO]    make4ht: No output directory
[INFO]    make4ht-lib: parse_lg process file: sample.tmp
[INFO]    make4ht-lib: tmp file
[STATUS]  make4ht: Conversion finished

See the [INFO] htlatex: Unsupported file: messages.

claell commented 9 months ago

I just tested again after updating make4ht. It seems that this is now supported by the package, and I don't need to manually use a configuration file, anymore? 😄

michal-h21 commented 8 months ago

@claell Yes, the support for adjustwidth is now built into TeX4ht.

claell commented 6 months ago

Closing this, then! Thanks again!