File: fen2latex.py

package info (click to toggle)
lyx 1.1.6fix4-2
  • links: PTS
  • area: contrib
  • in suites: woody
  • size: 26,136 kB
  • ctags: 13,679
  • sloc: cpp: 93,591; sh: 9,563; ansic: 8,253; perl: 3,489; makefile: 1,332; tcl: 163; sed: 150; python: 112; yacc: 38
file content (51 lines) | stat: -rw-r--r-- 897 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/python
#
# Copyright (C) 2000 The LyX Team.
#
# This file is distributed under the GPL license.
#
# This script will convert a chess position in the FEN
# format to a chunk of LaTeX to be used with the chess.sty
# style.

import sys,string,os

os.close(0)
os.close(1)
sys.stdin = open(sys.argv[1],"r")
sys.stdout = open(sys.argv[2],"w")

line = sys.stdin.readline()
if line[-1] == '\n':
    line = line[:-1]

line=string.split(line,' ')[0]
comp=string.split(line,'/')

first = 1
cont=1
margin= " "*6

for i in range(8):

    cont = cont + 1
    tmp=""
    for j in comp[i]:
	if j>='0' and j <= '9':
	    for k in range(int(j)):
		cont = cont + 1
		x, mod = divmod(cont,2)
		if mod : tmp = tmp + ' '
		else : tmp = tmp + '*'
	else :
	    tmp = tmp + j
	    cont = cont + 1

    if first: 
	first = 0
	print "\\board{"+tmp+"}"
    else : 
	print margin+"{"+tmp+"}"

print "\\showboard%"