5

I write articles on chess. I often need to describe a chess position, using a standard format named FEN, and would like it to be automatically converted to a png image, and when I export the org document as LaTeX or html the image to be inlined. I think it can be done because ditaa seems to work similarly.

For example, with the FEN string "8/pppr1kpp/8/8/8/5P2/PPP1RKPP/8 w - - 0 1" as input, I create a tex file named chessboard.tex:

\documentclass[border={0 0 3 0}, convert={density=150}]{standalone}
\usepackage{xskak}
\usepackage{chessboard}
\usepackage{chessfss}
\usepackage{fontspec}
\begin{document}

\setchessboard{normalboard, showmover=true, moverstyle=triangle, label=false}
\setboardfontfamily{merida}

\fenboard{8/pppr1kpp/8/8/8/5P2/PPP1RKPP/8 w - - 0 1} \chessboard

\end{document}

which, with the shell command $> xelatex --shell-escape chessboard.tex, produces the following png image (thanks to the use of the standalone package). enter image description here

How can I automate this process, so that I could put in an org file something like

#+BEGIN_SRC chessfen
8/pppr1kpp/8/8/8/5P2/PPP1RKPP/8 w - - 0 1
#+END_SRC

and have the above process automated?

manlio
  • 18,345
  • 14
  • 76
  • 126
engineerX
  • 2,914
  • 2
  • 18
  • 18

3 Answers3

2

Something like this?

#+title: Chess
#+startup: inlineimages
#+property: header-args:latex+ :imagemagick yes :iminoptions -density 300 -resize 400
#+property: header-args:latex+ :headers '("\\usepackage{chessboard}\\usepackage{xskak}\\usepackage{chessfss}") :border 1pt

* Chess

#+begin_src latex :file chess.png :results raw
\setchessboard{normalboard, showmover=true, moverstyle=triangle, label=false}
\fenboard{8/pppr1kpp/8/8/8/5P2/PPP1RKPP/8 w - - 0 1} \chessboard 
#+end_src
rvf0068
  • 1,339
  • 9
  • 19
  • 1
    Thank you for your answer. But it does not work for me, the latex source code is copied verbatim to the output. Reading a bit more, I think I need to write a new language for org-babel, which I am trying to do right now. – engineerX Oct 13 '14 at 14:25
0

This modification of rvf0068's answer works for me, after manually installing the necessary LaTeX packages (that can be found by inspecting in the error log output):

#+property: header-args:latex+ :headers '("\\usepackage{chessboard}\\usepackage{xskak}\\usepackage{chessfss}") :border 1pt

#+header: :imagemagick "t"
#+header: :results file raw
#+header: :exports results
#+header: :fit yes :border 0.5cm
#+header: :iminoptions -density 600 :imoutoptions -geometry 600
#+begin_src latex :file alburt_vs_kasparov_1978.png
\setchessboard{normalboard, showmover=false, moverstyle=triangle, label=false}
\fenboard{8/pppr1kpp/8/8/8/5P2/PPP1RKPP/8 w - - 0 1} \chessboard
#+end_src

# Local Variables:
# org-latex-pdf-process: ("xelatex -shell-escape -interaction=nonstopmode -output-directory=%o %f"
#                         "xelatex -shell-escape -interaction=nonstopmode -output-directory=%o %f"
#                         "xelatex -shell-escape -interaction=nonstopmode -output-directory=%o %f")
# End:
jco
  • 1,335
  • 3
  • 17
  • 29
0

I use LaTeX environments directly to typeset chess, with no src blocks:

Then, the white brings the king

- to the closest rank to the opposing king and
- to the file one next to that of the opposing king toward the center.

\begin{center}
  \fenboard{7k/R7/8/8/8/8/8/7K w - - 0 2}
  \mainline{2. Kg2 Kf8 3. Kf3 Ke8 4. Ke4 Kd8 5. Kd5 Kc8 6. Kd6}
  \par
  \showboard
\end{center}
Rudolf Adamkovič
  • 31,030
  • 13
  • 103
  • 118