3

I use skak to generate a beautiful chess book in PDF format. Unfortunately, Amazon Kindle does not import the PDF well. So, I have to make a Kindle friendly formatted book such as epub.

Is it possible to use the same latex source document to generate epub? If not, is there any other latex package that can help generate epub document for a chess book?

Here's the minimum sample document:

\documentclass[a4paper,11pt,oneside]{book}
\usepackage[utf8]{inputenc}
\usepackage{hyperref}
\hypersetup{
    colorlinks=true,
    linkcolor=[RGB]{41,41,41},
    filecolor=magenta,      
    urlcolor=cyan,
    pdftitle={Chess},
    bookmarks=true,
}
\usepackage[ps]{skak}
\showmoverOn
\begin{document}

\frontmatter
\title{My title}
\maketitle                
\tableofcontents                        
\mainmatter                             
\author{Sudheer}

\chapter{Introduction}
\newgame
\mainline{1.e4 c5 2.Nf3 g6 3.Bc4 Bg7 4.Ng5 e6}
\showboard

\end{document}

I am compiling using these steps:

 latex minimum.tex 
 dvips minimum.dvi 
 ps2pdf minimum.ps
3

You can use tex4ebook to create the ePub or mobi ebooks. It uses tex4ht for the conversion. tex4ht doesn't support skak package out of the box, but it is easily configurable, so we can add the support ourselves.

There are two things which needs to be addressed: the chess figures in the text, and the chessboards. The chess figures can be converted as Unicode characters, the chessboards must be converted as images.

The figures use a special font, which needs to be configured in tex4ht. Save the following text as SkakNew.htf and put it to the directory with your document:

SkakNew  32 121
'' ''     32
'!' ''     33
'”' ''     34
'#' ''  35
'$' ''  36
'%' ''  37
'&' ''  38
'’' ''     39
'(' ''  40
')' ''  41
'*' ''  42
'+' ''  43
',' ''  44
'-' ''  45
'.' ''  46
'/' ''     47
'0' ''  48
'1' ''  49
'2' ''  50
'3' ''  51
'4' ''  52
'5' ''  53
'6' ''  54
'7' ''  55
'8' ''  56
'9' ''  57
':' ''  58
';' ''  59
'¡' ''     60
'=' ''  61
'¿' ''     62
'?' ''  63
'@' ''  64
'→' ''  65
'♗' ''  66
'↑' ''  67
'⊙' ''  68
'△' ''  69
'□' ''  70
'⇗' ''  71
'⇔' ''  72
'⊞' ''  73
'╳' ''  74
'♔' ''  75
'⟂' ''  76
'≪' ''  77
'♘' ''  78
'≫' ''  79
'Ⅱ' ''  80
'♕' ''  81
'♖' ''  82
'>' ''  83
'⊕' ''  84
'○' ''  85
'⇆' ''  86
'W' ''  87
'×' ''  88
'Y' ''  89
'Z' ''  90
'[' ''  91
'“' ''     92
']' ''  93
'ˆ' ''     94
'˙' ''     95
'‘' ''     96
'⧉' ''  97
'⌓' ''  98
'±' ''  99
'⦂' ''  100
'∓' ''  101
'⩲' ''  102
'⩱' ''  103
'h' ''  I cannot find it, it is plus followed by minus
'i' ''  minus followed by plus
'=' ''  106
'k' ''  107
'l' ''  108
'#' ''  109
'n' ''  110
'o' ''  111
'p' ''  112
'q' ''  113
'r' ''  114
's' ''  115
't' ''  116
'u' ''  117
'v' ''  118
'w' ''  119
'x' ''  120
'y' ''  121
SkakNew  32 121

The images for chess boards can be requested with the following configuration. Save it as skak.4ht and save it to your document's dir as well:

\NewConfigure{SkakBoard}{2}

\pend:def\showboard{\a:SkakBoard}
\append:def\showboard{\b:SkakBoard}

\Configure{SkakBoard}{\Picture+{}}{\EndPicture}

\endinput

It just patches command \showboard to include special tex4ht commands which convert enclosed content as images.

You can compile your document to mobi using the following comamand. Note that you need to have kindlegen installed:

 tex4ebook -f mobi  minimum.tex

The result is following, shown in Calibre:

enter image description here

To get better picture quality, you can try to add the following line to the skak.4ht file (before \endinput):

\Configure{Picture}{.svg}

It will request the graphics in the svg format:

enter image description here

One last note: I got invalid ePub file because you used \author after maketitle, you should put it before it.

Edit:

If you want to use more commands which print to one canvas, you need to enclose them in custom environment, whose contents will be converted as an image:

\documentclass[a4paper,11pt,oneside]{book}
\usepackage[utf8]{inputenc}
\usepackage{hyperref}
\hypersetup{
    colorlinks=true,
    linkcolor=[RGB]{41,41,41},
    filecolor=magenta,      
    urlcolor=cyan,
    pdftitle={Chess},
    bookmarks=true,
}
\usepackage[ps]{skak}
\showmoverOn
\newenvironment{mymoves}{}{}
\begin{document}

\frontmatter
\title{My title}
\author{Sudheer}
\maketitle                
\tableofcontents                        
\mainmatter                             

\chapter{Introduction}
\newgame
\mainline{1.e4 c5 2.Nf3 g6 3.Bc4 Bg7 4.Ng5 e6}
\begin{mymoves}
\showboard
\printarrow{a1}{a8}
\end{mymoves}

\end{document}

The important part here is:

\begin{mymoves}
\showboard
\printarrow{a1}{a8}
\end{mymoves}

You can configure the mymoves environment in the config file:

\Preamble{xhtml}
\Configure{Picture}{.svg}
\ConfigureEnv{mymoves}{\Picture*{}}{\EndPicture}{}{}
\begin{document}

\EndPreamble

Note that it seems that this sample needs to use the SVG output, it seems that dvipng doesn't support some PostScript.

The result:

enter image description here

  • michal.h21, Thanks. That helps a lot already. The image you have posted is better than the one I generated. The one I generated has a white line(arc) on top left corner of dark squares. I wonder what is wrong in my setup. I copied and pasted the configs you mentioned. ibb.co/e4DXfk is an example – Sudheer May 2 '17 at 16:08
  • @Sudheer it is possible that you have older version of tex4ht, it uses different way to generate the images. it should be fixed in the updated TeX Live. – michal.h21 May 2 '17 at 18:52
  • I noticed one other issue, the board ornaments do not appear in .mobi. Arrows, circles, etc do not appear. – Sudheer May 3 '17 at 7:39
  • @Sudheer do you have any example? – michal.h21 May 3 '17 at 8:27
  • yes, after \showboard just the command: \printarrow{a1}{a8}. Here's the PDF screenshot: ibb.co/eCzm6Q – Sudheer May 3 '17 at 11:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.