Skip to content

Instantly share code, notes, and snippets.

@michal-h21
Last active October 9, 2019 18:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michal-h21/293d567ce11e1f1eba0112d908a26245 to your computer and use it in GitHub Desktop.
Save michal-h21/293d567ce11e1f1eba0112d908a26245 to your computer and use it in GitHub Desktop.
tex4ht configuraton file for xskak.sty. compile with `make4ht sample.tex svg`
\documentclass[12pt]{article}
\ifdefined\HCode
\def\pgfsysdriver{pgfsys-dvisvgm4ht.def}
\fi
\usepackage{xskak}
\begin{document}
\newchessgame[id=main]
\chessboard
\end{document}
\NewConfigure{chessboard}{2}
% this should put configurable hooks around \newchessgame
% contents printed by this command should be printed to image
% \newcommand\:tempaboard[1][]{\a:chessboard\o:newchessgame:[#1]\b:chessboard}
\newcommand\Save:TikzPict{\let\old:a:tikzpicture\a:tikzpicture\let\old:b:tikzpicture\b:tikzpicture\let\a:tikzpicture\relax\let\b:tikzpicture\relax}
\newcommand\Restore:TikzPict{\let\a:tikzpicture\old:a:tikzpicture\let\b:tikzpicture\old:b:tikzpicture}
\newcommand\:tempaboard[1][]{\a:chessboard\o:chessboard:[#1]\b:chessboard}
%
\HLet\chessboard\:tempaboard
\Configure{chessboard}{\Picture*{}\Save:TikzPict}{\Restore:TikzPict\EndPicture}
\Hinput{chessboard}
@u-fischer
Copy link

I can create working svg files with dvisvgm with the command dvisvgm --no-fonts sample.dvi, but I don't know how to pass the no-fonts option through make4ht.

@michal-h21
Copy link
Author

I think I've found a solution:

\NewConfigure{chessboard}{2}

% this should put configurable hooks around \newchessgame
% contents printed by this command should be printed to image
% \newcommand\:tempaboard[1][]{\a:chessboard\o:newchessgame:[#1]\b:chessboard}
\newcommand\:tempaboard[1][]{\a:chessboard\o:chessboard:[#1]\b:chessboard}
% 
\HLet\chessboard\:tempaboard

\Configure{chessboard}{\typeout{patching works}\Picture*{}}{\EndPicture}
\Hinput{chessboard}

The strange thing is that I tried to patch the \chesboard command first and it failed.

@u-fischer
Copy link

The chessboard looks fine now. But when I add "decoration" there is a displacement:

image

The code is

\documentclass[12pt]{article}
\ifdefined\HCode
  \def\pgfsysdriver{pgfsys-dvisvgm4ht.def}
\fi

\usepackage{xskak}
\begin{document}
\def\pawnranks{a2-h2,h7-a7}
\chessboard[inverse,%
pgfstyle=border,%
markregions={\pawnranks},%
color=red,padding=0.3ex,
linewidth=0.1ex,%
backregions={\board,d4-e5},%
pgfstyle=text,%
text=$\leftarrow$%
\currentbk\currentwq
$\rightarrow$,%
markregion=a3-h3,%
pgfstyle={[rotate=45]text},%
backregion=h8-a1%
]
\end{document}

When I process directly with dvisvgm (with dvisvgm as document option) it looks ok (but the red color is gone).

@michal-h21
Copy link
Author

It seems that this may be used by nested \Picture* commands, as they are used by the configuration for tikzpicture as well. Turning off this configuration seems to do the trick:

\NewConfigure{chessboard}{2}

% this should put configurable hooks around \newchessgame
% contents printed by this command should be printed to image
% \newcommand\:tempaboard[1][]{\a:chessboard\o:newchessgame:[#1]\b:chessboard}
\newcommand\Save:TikzPict{\let\old:a:tikzpicture\a:tikzpicture\let\old:b:tikzpicture\b:tikzpicture\let\a:tikzpicture\relax\let\b:tikzpicture\relax}
\newcommand\Restore:TikzPict{\let\a:tikzpicture\old:a:tikzpicture\let\b:tikzpicture\old:b:tikzpicture}
\newcommand\:tempaboard[1][]{\a:chessboard\o:chessboard:[#1]\b:chessboard}
% 
\HLet\chessboard\:tempaboard
\Configure{chessboard}{\Picture*{}\Save:TikzPict}{\Restore:TikzPict\EndPicture}
\Hinput{chessboard}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment