Quantcast
Channel: Parsing a Flat SGF String (with the Package listofitems) - TeX - LaTeX Stack Exchange
Viewing all articles
Browse latest Browse all 3

Parsing a Flat SGF String (with the Package listofitems)

$
0
0

I'm trying to parse an SGF string with the package listofitems. SGFs are trees in text form, but right now, I'm working on only single-branched SGFs, for simplicity.

Here's an example of what I'm trying to do:

\documentclass{article}\usepackage{listofitems}\usepackage{tikz}\newcommand{\parseSgf}[1]{  % From [this answer by @StevenB.Segletes](https://tex.stackexchange.com/a/429895/64441).  \setsepchar{;}  \defpair{[]}  \readlist\Z{#1}  \begin{itemize}    \foreach \i in {\Z}{      % TODO: if key is either `B` or `W`:      \item Color: {\i}[0] and Coords: {\i}[1]    }  \end{itemize}}\begin{document}  \def\sgfA{;B[ab];W[cd]}  \def\sgfB{(;GM[1]FF[4]CA[UTF-8]AP[Sabaki:0.52.2]KM[6.5]SZ[19]DT[2024-02-05];B[as];W[bs];B[cs])}  \parseSgf{\sgfA}  \parseSgf{\sgfB}\end{document}

sgfA isn't proper SGF, just a simple example. I would like it to print an unordered list like this:

  • Color: B and Coords: ab
  • Color: W and Coords: cd

But I haven't been able to figure out how to use \setsepchar and \defpair to separate things properly, or how to use them in a \foreach.

sgfB is a proper SGF string. And there's the additional problem of ignoring keys that are not B or W. If anyone knows how to do it with listofitems, that would be a plus.


Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles



Latest Images