summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/braille/grade1.py
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2010-02-22 00:10:04 +0000
committerKarl Berry <karl@freefriends.org>2010-02-22 00:10:04 +0000
commit61b9a033612870341c0c8dfe6e57be54f38dde44 (patch)
tree1283b822261972c87af885c38b4b219b15285868 /Master/texmf-dist/doc/latex/braille/grade1.py
parent72065e8744a9375ec9921de71bb2e3ace90b5e19 (diff)
braille doc update (20feb10)
git-svn-id: svn://tug.org/texlive/trunk@17130 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/doc/latex/braille/grade1.py')
-rw-r--r--Master/texmf-dist/doc/latex/braille/grade1.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/Master/texmf-dist/doc/latex/braille/grade1.py b/Master/texmf-dist/doc/latex/braille/grade1.py
new file mode 100644
index 00000000000..925c2514e8d
--- /dev/null
+++ b/Master/texmf-dist/doc/latex/braille/grade1.py
@@ -0,0 +1,55 @@
+"""
+Converts ASCII text to Grade 1 Braille as described in
+ braille.sty, summary.tex
+Essentially, it marks up
+ {Letter}, {Number},
+ {``}...{''} for double quotation which must be typed as ``...'',
+ {.`}...{'.} for single quotation which must be typed as .`...'.,
+ {percent}
+so that the text is acceptable as input to \braille{}. The output is
+striped and returned all in one line.
+
+Usage:
+>>> grade1.convert("I like computer")
+"I like computer"
+>>> grade1.convert("April 1999")
+"April {Number}1999"
+>>> grade1.convert("I said ``hello'', and she said ``goodbye''.")
+"I said {``}hello{''}, and she said {``}goodbye{''}."
+
+Usage:
+ python grade1.py < text > tags
+"""
+import string
+
+Number = '0123456789'
+
+def convert(line):
+ line = string.replace(line, "``", "{``}") # ``...''
+ line = string.replace(line, "''", "{''}")
+ line = string.replace(line, ".`", "{.`}") # .`...'.
+ line = string.replace(line, "'.", "{'.}")
+ line = string.replace(line, '%', '{percent}') # %
+ s, oldi, oldii, skipchars = '', ' ', ' ', 0
+ for i in line:
+ if i == '{':
+ skipchars = 1
+ elif i == '}':
+ skipchars = 0
+ elif skipchars: # skip anything inside {...}
+ pass
+ elif oldi in Number and i in 'abcdefghij':
+ s = s + '{Letter}'
+ elif i in Number:
+ if (oldii in Number and oldi in '.-') or (oldi in Number):
+ pass
+ else:
+ s = s + '{Number}'
+ s, oldi, oldii = s + i, i, oldi
+ return string.join(string.split(s)) # return all in one line
+
+
+if __name__ == '__main__':
+ import sys
+ line = sys.stdin.read() # swallow the whole thing
+ print convert(line) # may produce extra \n