i want to rotate text within a table, which works fine when generating a pdf document, but not when using tex4ht. Is there a way to fix this?
MWE:
\documentclass{book}
\usepackage{mwe}
\begin{document}
\rotatebox{90}{text}
\end{document}
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityi want to rotate text within a table, which works fine when generating a pdf document, but not when using tex4ht. Is there a way to fix this?
MWE:
\documentclass{book}
\usepackage{mwe}
\begin{document}
\rotatebox{90}{text}
\end{document}
We can use the CSS transform
property together with rotate()
function to rotate boxes in HTML. You can try the following configuration file graphicx.4ht
:
% graphicx.4ht (2017-10-21-16:16), generated from tex4ht-4ht.tex
% Copyright 2003-2009 Eitan M. Gurari
% Copyright 2009-2017 TeX Users Group
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3c of this license or (at your option) any
% later version. The latest version of this license is in
% http://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions
% of LaTeX version 2005/12/01 or later.
%
% This work has the LPPL maintenance status "maintained".
%
% The Current Maintainer of this work
% is the TeX4ht Project <http://tug.org/tex4ht>.
%
% If you modify this program, changing the
% version identification would be appreciated.
\immediate\write-1{version 2017-10-21-16:16}
\let\Gin:esetsize\Gin@esetsize
\def\Gin@esetsize{%
\ifx \Gin@ewidth\Gin@exclamation
\let\Gin:ewidth\Gin@ewidth
\else
\setlength\tmp:dim\Gin@ewidth
\edef\Gin:ewidth{\the\tmp:dim}%
\fi
\ifx \Gin@eheight\Gin@exclamation
\let\Gin:eheight\Gin@eheight
\else
\setlength\tmp:dim\Gin@eheight
\edef\Gin:eheight{\the\tmp:dim}%
\fi
\Gin:esetsize
}
\DeclareGraphicsRule{.png}{bmp}{.xbb}{}
\DeclareGraphicsRule{.jpg}{bmp}{.xbb}{}
\DeclareGraphicsRule{.gif}{bmp}{.xbb}{}
\DeclareGraphicsRule{.pdf}{bmp}{.xbb}{}
\DeclareGraphicsRule{.svg}{bmp}{.xbb}{}
\NewConfigure{rotatebox}{2}
\pend:def\Grot@box{\a:rotatebox}
\append:def\Grot@box{\b:rotatebox}
\Configure{rotatebox}{\HCode{<span class="rotatebox" style="transform: rotate(-\Grot@angle deg);">}}{\HCode{</span>}}
\Css{.rotatebox{
display: inline-block;}}
\Hinput{graphicx}
\endinput
The important code is the following:
\NewConfigure{rotatebox}{2}
\pend:def\Grot@box{\a:rotatebox}
\append:def\Grot@box{\b:rotatebox}
\Configure{rotatebox}{\HCode{<span class="rotatebox" style="transform: rotate(-\Grot@angle deg);">}}{\HCode{</span>}}
\Css{.rotatebox{
display: inline-block;}}
A new tex4ht
configuration, rotatebox
has been declared and the configuration hooks have been inserted to the \Grot@box
command, which is used to draw the rotated box. The hooks are then configured to insert the <span class="rotatebox">
element with style="transform: rotate(-\Grot@angle deg);"
CSS style. This style enables the rotation. The \Grot@angle
command contains the rotation angle, which must be negative for some reason in the CSS.
The following TeX code:
\documentclass{book}
\usepackage{mwe}
\begin{document}
normal text
\rotatebox{90}{text}
\rotatebox{190}{some longer text}
normal text continues
\end{document}
will be rendered in this way in HTML:
In PDF, it looks a bit different:
The problem is that things started to go wrong when I tried to use a different point of rotation than the center, so I think this is the best we can get.
Edit:
If your Epub viewer doesn't support rotations (just a proof of the poor support ebooks still receive), you can convert the rotated text to an image. Try the following config file:
\Preamble{xhtml,svg}
\Configure{rotatebox}{\Picture+{}}{\EndPicture}
\begin{document}
\EndPreamble
The result: