diff --git a/jaws/modified_by_istvan/latex.JCF b/jaws/modified_by_istvan/latex.JCF new file mode 100644 index 0000000..d22fe17 --- /dev/null +++ b/jaws/modified_by_istvan/latex.JCF @@ -0,0 +1,7 @@ +[Braille] +Grade2Translation=0 +BrailleMoveActiveCursor=1 +BrailleTranslationType=1 +ContractedBrailleInput=0 +[Options] +Scheme=latex diff --git a/jaws/modified_by_istvan/latex.JSS b/jaws/modified_by_istvan/latex.JSS new file mode 100644 index 0000000..9f7c416 --- /dev/null +++ b/jaws/modified_by_istvan/latex.JSS @@ -0,0 +1,258 @@ +; latex.jss +; A part of the latex-access project at http://latex-access.sourceforge.net/ +; Author: Alastair Irving +; Modified by: István Velegi +; Copyright (C) 2011 Alastair Irving/latex-access Contributors +; +; This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; +; either version 2 of the License, or (at your option) any later version. +; +; This program is distributed in the hope that it will be useful, +; but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +; See the GNU General Public License for more details. +; +; You should have received a copy of the GNU General Public License along with this program; if not, visit +; + + +; Documentation by: Jose Tamayo( jtblas@hotmail.com) +; +; history of changes +; +; Needs: +; 1. JSM file for messages +; 2. proper variable naming +; 3. intro for functions. +; 4. Hungarian notation +; 5. Move all literals and messages to the latex.jsm file. + + +include "hjconst.jsh" + + include "latex.jsm" + +globals int initialised, +int ProcessMaths, +object latex_access, +object matrix, +int row, +int column + +Void Function AutoStartEvent () +if !initialised then +let latex_access=CreateObject (o_latexAccess) +let initialised=true +endif +EndFunction + + +Script reInitialise () +let latex_access=CreateObject (o_latexAccess) +sayMessage(1, msgReInit_s); +EndScript + + +Void Function SayLine () +if ProcessMaths then +var string input +let input = GetLine () + +if StringIsBlank(input) then +let input = "blank" +else +let input = latex_access.speech(input) +let input = StringReplaceSubstrings (input, "&", "&") +let input = StringReplaceSubstrings (input, "", smmGetStartMarkupForAttributes (attrib_subscript|attrib_text)) +let input = StringReplaceSubstrings (input, "", smmGetEndMarkupForAttributes (attrib_subscript|attrib_text)) +let input = StringReplaceSubstrings (input, "", smmGetStartMarkupForAttributes (attrib_superscript|attrib_text)) +let input = StringReplaceSubstrings (input, "", smmGetEndMarkupForAttributes (attrib_superscript|attrib_text)) +let input = StringReplaceSubstrings (input, "", smmGetStartMarkupForAttributes (attrib_bold|attrib_text)) +let input = StringReplaceSubstrings (input, "", smmGetEndMarkupForAttributes (attrib_bold|attrib_text)) +let input=StringReplaceSubstrings (input, "", smmGetStartMarkupForAttributes (attrib_double_strikeout|attrib_text)) +let input=StringReplaceSubstrings (input, "", smmGetEndMarkupForAttributes (attrib_double_strikeout|attrib_text)) +endif +Say (input, ot_selected_item, true) +else +SayLine () +endif +EndFunction + +Script ToggleMaths () +if ProcessMaths then +let ProcessMaths = false +SayMessage (ot_status, msgProcessingOff_L, msgProcessingOff_S) +else +let ProcessMaths = true +SayMessage(OT_STATUS,msgProcessingOn_L,msgProcessingOn_S) +endif + +EndScript + +Script ToggleDollarsBraille () +var int result +let result=latex_access.toggle_dollars_nemeth() +if result==-1 then +SayMessage (ot_status, msgBrailleDollarsOff_L, msgBrailleDollarsOff_S) +else +SayMessage (ot_status, msgBrailleDollarsOn_L, msgBrailleDollarsOn_S) +endif +EndScript + +Script ToggleDollarsSpeech () +var int result +let result=latex_access.toggle_dollars_speech() +if result==-1 then +SayMessage (ot_status, msgSpeechDollarsOff_L, msgSpeechDollarsOff_S) +else +SayMessage (ot_status, msgSpeechDollarsOn_L, msgSpeechDollarsOn_S) +endif +EndScript + +Int Function BrailleBuildLine () +if ProcessMaths then +var string input +let input = GetLine() +let input = StringReplaceSubstrings (input, sScrollDownSymbols , "") +let input=StringTrimTrailingBlanks (input) +let input = latex_access.nemeth(input) +; now sort out bad dots 456 +let input =StringReplaceSubstrings (input, "_", "\127") +BrailleAddString (input, 0, 0, 0) + +endif +return true +EndFunction + +Script InputMatrix () +let matrix=CreateObject (o_latex_access_matrix) +let row=1 +let column=1 +matrix.tex_init(GetSelectedText ()) +; JT: Replace the msg var with a message variable in the latex.jsm file +var string msg +let msg ="Initialised " +let msg=msg+inttostring(matrix.rows) +let msg=msg+sPadBy +let msg=msg+inttostring(matrix.columns) +let msg=msg +sPadMatrix +SayString(msg) +EndScript + +Script HotKeyHelp () +; check the virtual buffer and close it if active. +If UserBufferIsActive () Then + UserBufferDeactivate () +EndIf +; Display the help text when the user presses JAWSKey+H +SayFormattedMessage(OT_USER_BUFFER, msgHotKeyHelp) +AddHotKeyLinks () +EndScript + +Script MatrixRight () +if column < matrix.columns then +let column = column+1 +saystring(matrix.get_cell(row,column)) +else +saystring(sEndRow) +endif +EndScript + +Script MatrixLeft () +if column > 1 then +let column = column - 1 +saystring(matrix.get_cell(row,column)) +else +saystring(sStartRow) +endif +EndScript + +Script MatrixDown () +if row < matrix.rows then +let row = row+1 +saystring(matrix.get_cell(row,column)) +else +saystring(sEndColumn) +endif +EndScript + +Script MatrixUp () +if row > 1 then +let row = row - 1 +saystring(matrix.get_cell(row,column)) +else +SayString(sStartColumn) +endif +EndScript + +; JT: This variable named i must be changed +Script SayRow (int i) +if i>0 && i <= matrix.rows then +saystring(matrix.get_row(i," ")) +else +saystring(sInvalidRow) +endif +EndScript +; JT: Find out what i is for and replace if needed. +Script SayColumn (int i) +if i>0 && i <=matrix.columns then +saystring(matrix.get_col(i," ")) +else +saystring(sInvalidColumn) +endif +EndScript + +Script preprocessorAdd () +var string input, int args, string strargs, string translation +if InputBox (sCommandToRedefine, "Initial LaTeX", input) then +if InputBox (sEnterCommandArguments, "Number of arguments", strargs) then +if InputBox (sEnterCustomCommandDef, "Translation", translation) then +let args=StringToInt (strargs) +latex_access.preprocessor_add(input,args,translation) +endif +endif +endif +EndScript + + +Script PreprocessorFromString () +latex_access.preprocessor_from_string(GetSelectedText ()) + + +EndScript + + + +Script PreprocessorWrite () +var string filename +if InputBox (sEnterFileToSaveTo , "Filename", filename) then +if FileExists (filename) then +var int result +let result=ExMessageBox (sFileExistError , sFileExistTitle , MB_YESNO) +if result==IDNO then +return +endif +endif +latex_access.preprocessor_write(filename) +endif +EndScript + + +Script PreprocessorRead () +var string filename +; JT: another literal to move to the latex.jsm file. +if InputBox ("enter full filename to read from ", "Filename", filename) then +if FileExists (filename) then +latex_access.preprocessor_read(filename) +else +MessageBox (sFileNoExist ) +endif +endif +EndScript + + + + + + + + diff --git a/jaws/modified_by_istvan/latex.jbs b/jaws/modified_by_istvan/latex.jbs new file mode 100644 index 0000000..e69de29 diff --git a/jaws/modified_by_istvan/latex.jkm b/jaws/modified_by_istvan/latex.jkm new file mode 100644 index 0000000..2ec60c8 --- /dev/null +++ b/jaws/modified_by_istvan/latex.jkm @@ -0,0 +1,33 @@ +[Common Keys] +Control+M=ToggleMaths +Control+Shift+M=InputMatrix +Control+Shift+L=MatrixRight +Control+Shift+J=MatrixLeft +Control+Shift+K=MatrixDown +Control+Shift+I=MatrixUp +Control+Shift+1=SayRow(1) +Control+Shift+2=SayRow(2) +Control+Shift+3=SayRow(3) +Control+Shift+4=SayRow(4) +Control+Shift+5=SayRow(5) +Control+Shift+6=SayRow(6) +Control+Shift+7=SayRow(7) +Control+Shift+8=SayRow(8) +Control+Shift+9=SayRow(9) +Control+Alt+1=SayColumn(1) +Control+Alt+2=SayColumn(2) +Control+Alt+3=SayColumn(3) +Control+Alt+4=SayColumn(4) +Control+Alt+5=SayColumn(5) +Control+Alt+6=SayColumn(6) +Control+Alt+7=SayColumn(7) +Control+Alt+8=SayColumn(8) +Control+Alt+9=SayColumn(9) +Control+Shift+D=ToggleDollarsSpeech +Control+Shift+R=PreprocessorRead +Control+Shift+A=preprocessorAdd +Control+Shift+W=PreprocessorWrite +Control+Shift+H=PreprocessorFromString +Insert+H=HotKeyHelp +Control+Alt+Shift+R=reInitialise +Control+D=ToggleDollarsBraille diff --git a/jaws/modified_by_istvan/latex.jsb b/jaws/modified_by_istvan/latex.jsb new file mode 100644 index 0000000..a57ed71 Binary files /dev/null and b/jaws/modified_by_istvan/latex.jsb differ diff --git a/jaws/modified_by_istvan/latex.jsd b/jaws/modified_by_istvan/latex.jsd new file mode 100644 index 0000000..014cadd --- /dev/null +++ b/jaws/modified_by_istvan/latex.jsd @@ -0,0 +1,56 @@ +:function AutoStartEvent + +:script reInitialise +:Synopsis Loads the COM object again. +:Description Run this if there is no speech or Braille. + +:function SayLine +:Synopsis An overidden version of the default, which processes maths before it is spoken. + +:script ToggleMaths +:Synopsis Toggles the speaking of mathematical expressions as either straight latex or a more verbal rendering. + +:script ToggleDollarsBraille +:Synopsis Toggles whether or not dollars are removed in braille. + +:script ToggleDollarsSpeech +:Synopsis Toggles the speaking of dollars. + +:function BrailleBuildLine +:Returns int No Return Description + +:script InputMatrix +:Synopsis Highlight a matrix and then run this script to have it created as an object. + +:script HotKeyHelp + +:script MatrixRight +:Synopsis Moves the matrix cursor to the right and speaks the new cell. + +:script MatrixLeft +:Synopsis Moves the matrix cursor to the left and speaks the new cell. + +:script MatrixDown +:Synopsis Moves the matrix cursor down and speaks the cell. + +:script MatrixUp +:Synopsis Moves the matrix cursor up and speaks the cell. + +:script SayRow +:Synopsis Speaks the required row of the matrix. + +:script SayColumn +:Synopsis Says the required column of the matrix + +:script preprocessorAdd +:Synopsis Adds a custom command to the preprocessor. + +:script PreprocessorFromString +:Synopsis adds commands defined in the highlighted text to the preprocessor. + +:script PreprocessorWrite +:Synopsis Saves the preprocessor to a file. + +:script PreprocessorRead +:Synopsis Reads preprepreprocessor entries from a file. + diff --git a/jaws/modified_by_istvan/latex.jsm b/jaws/modified_by_istvan/latex.jsm new file mode 100644 index 0000000..b1084d8 --- /dev/null +++ b/jaws/modified_by_istvan/latex.jsm @@ -0,0 +1,133 @@ +; latex.jsm +; A part of the latex-access project at http://latex-access.sourceforge.net/ +; Author: Alastair Irving +; Modified by: Istvan Velegi +; Copyright (C) 2011 Alastair Irving/latex-access Contributors +; +; This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; +; either version 2 of the License, or (at your option) any later version. +; +; This program is distributed in the hope that it will be useful, +; but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +; See the GNU General Public License for more details. +; +; You should have received a copy of the GNU General Public License along with this program; if not, visit +; +; Created by Jose Tamayo on 2/25/2010 +; this will allow for latex-access to load the messages and vars correctly. + +const +o_latexAccess = "latex_access", +o_latex_access_matrix = "latex_access_matrix", +; input variable literals +sScrollDownSymbols = "scroll down symbol", +sPadBy = " by ", +sPadMatrix = " matrix ", +sEndRow = "end row", +sStartRow = "start row", +sEndColumn = "end column", +sStartColumn = "start column", +sInvalidRow = "Invalid Row", +sInvalidColumn = "invalid column", +sCommandToReDefine = "Enter the command you wish to re-define.", +sEnterCommandArguments = "Enter the number of arguments of the command.", +sEnterCustomCommandDef = "Enter the definition of the custom command, that is, the standard LaTeX to which it is equivalent.", +sEnterFileToSaveTo = "enter full filename to save to", +sFileExistError = "The file you specified already exists. Do you wish to replace it?", +sFileExistTitle = "File Exists", +sFileNoExist = "File does not exist", +;keystrokes +ks1 = "control+shift+d" ;open default file + +messages +@msgReInit_s +LaTeX addon has been re-initialised. +@@ +@msgReInit_l +LaTeX addon has been re-initialised. +@@ +@msgProcessingOn_S +Processing on +@@ +@msgProcessingOn_L +Maths to be processed to a more verbal form +@@ +@msgProcessingOff_S +Processing off +@@ +@msgProcessingOff_L +maths to be read as plain latex +@@ +@msgBrailleDollarsOff_S +Braille Dollars off +@@ +@msgBrailleDollarsOff_L +Dollars will now be ignored in braille +@@ +@msgBrailleDollarsOn_S +Braille Dollars on +@@ +@msgBrailleDollarsOn_L +Dollars will now be shown in braille +@@ + +@msgSpeechDollarsOff_S +Speech Dollars off +@@ +@msgSpeechDollarsOff_L +Dollars will now be ignored in speech +@@ +@msgSpeechDollarsOn_S +Speech Dollars on +@@ +@msgSpeechDollarsOn_L +Dollars will now be shown in Speech +@@ + +; JT HERE +; Hot key help for latex-access +@msgHotKeyHelp +Welcome to the LaTeX Access Tools for JAWS. + +NOTE: There is currently no means of independently toggling of speech and braille. + +Press %KeyFor(ToggleMaths ) to toggle processing of LaTeX on and off +Press %KeyFor(ToggleDollarsBraille ) To toggle Braille dollars on or off +Press %KeyFor(ToggleDollarsSpeech ) To toggle Speech dollars on or off +Press %KeyFor(InputMatrix ) to create a matrix + +the Preprocessor +LaTeX enables you to define custom commands. The scripts can handle +this but they must be told what the custom commands are. This is done +by means of the preprocessor. + +Press %KeyFor(preprocessorAdd ) to add a preprocessor command + +In the first textbox, enter the custom command, in the next enter the number of arguments, 0 if there +are none, and in the 3rd box enter the translation of the custom +command. The translation is the standard LaTeX equivalent of the +command, using #n to denote places where the nth argument should be +interpolated into the translation. The 3 textboxes correspond to the +3 arguments to the \newcommand command used to define the custom +command. + +Preprocessor commands are lost when JAWS is restarted. You may load multiple preprocessor files. +Press %KeyFor(PreprocessorWrite ) to save the custom preprocessor commands to a file. +Press %KeyFor(PreprocessorRead ) to retreive custom preprocessor commands previously saved + +The Matrix Processor +To load a matrix into the processor, highlight its contents, (not +including any \begin and \end commands), and press %KeyFor(InputMatrix ) . For +example you might highlight the following: + +1 & 2\\ +3 & 4\\ + +CTRL+SHIFT+j, K, L, or I act as arrows that navigate the matrix +CTRL+SHIFT with a number reads that row +cTRL+ALT with a number reads that column. + +Press %KeyFor(HotKeyHelp ) to redisplay this message +@@ + +EndMessages diff --git a/jaws/modified_by_istvan/latex.smf b/jaws/modified_by_istvan/latex.smf new file mode 100644 index 0000000..6bc6d71 --- /dev/null +++ b/jaws/modified_by_istvan/latex.smf @@ -0,0 +1,127 @@ +[Attribute Behavior Table] +default=0|MessageVoice||| +3=3|||BoldVoice| +1025=3|||DoubleStrikeoutVoice| +2049=3|||SuperscriptVoice| +4097=3|||SubscriptVoice| +5=3|||ItalicVoice| +[Indentation Behavior Table] +default=1|MessageVoice||| +[HTML Attribute Behavior Table] +onclick=1|NormalVoice:clickable||| +onmouseover=1|NormalVoice:on mouse over||| +visited=1|NormalVoice:visited||| +[Other Behavior Table] +Cap=3|NormalVoice||SingleCapVoice| +AllCaps=3|NormalVoice||AllCapsVoice| +Repetition=1|MessageVoice||| +Spell=3|||SpellingVoice| +Quote=3|||NormalVoice| +[Font Size Behavior Table] +default=0|MessageVoice||| +[Font Name Behavior Table] +default=0|MessageVoice||| +[Color Behavior Table] +default=0|MessageVoice||| +[ControlType Behavior Table] +1=1|NormalVoice||| +2=1|NormalVoice||| +3=1|NormalVoice||| +4=1|NormalVoice||| +5=1|NormalVoice||| +6=1|NormalVoice||| +7=1|NormalVoice||| +8=1|NormalVoice||| +9=1|NormalVoice||| +10=1|NormalVoice||| +11=1|NormalVoice||| +12=1|NormalVoice||| +13=1|NormalVoice||| +14=1|NormalVoice||| +15=1|NormalVoice||| +16=1|NormalVoice||| +17=1|NormalVoice||| +18=1|NormalVoice||| +19=1|NormalVoice||| +20=1|NormalVoice||| +21=1|NormalVoice||| +22=1|NormalVoice||| +23=1|NormalVoice||| +24=1|NormalVoice||| +25=1|NormalVoice||| +26=1|NormalVoice||| +27=1|NormalVoice||| +28=1|NormalVoice||| +29=1|NormalVoice||| +30=1|NormalVoice||| +31=1|NormalVoice||| +32=1|NormalVoice||| +33=1|NormalVoice||| +34=1|NormalVoice||| +35=1|NormalVoice||| +36=1|NormalVoice||| +37=1|NormalVoice||| +38=1|NormalVoice||| +39=1|NormalVoice||| +40=1|NormalVoice||| +41=1|NormalVoice||| +42=1|NormalVoice||| +43=1|NormalVoice||| +44=1|NormalVoice||| +45=1|NormalVoice||| +46=1|NormalVoice||| +47=1|NormalVoice||LinkVoice| +48=1|NormalVoice||LinkVoice| +49=1|NormalVoice||LinkVoice| +50=1|NormalVoice||LinkVoice| +51=1|NormalVoice||| +52=1|NormalVoice||| +53=1|NormalVoice||| +54=1|NormalVoice||| +55=1|NormalVoice||| +56=1|NormalVoice||| +57=1|NormalVoice||| +58=1|NormalVoice||| +59=1|NormalVoice||| +60=1|NormalVoice||| +61=1|NormalVoice||| +62=1|NormalVoice||| +63=1|NormalVoice||| +64=1|NormalVoice||| +65=1|NormalVoice||| +66=1|NormalVoice||| +67=1|NormalVoice||| +68=1|NormalVoice||HeadingLevel1Voice| +69=1|NormalVoice||HeadingLevel2Voice| +70=1|NormalVoice||HeadingLevel3Voice| +71=1|NormalVoice||HeadingLevel4Voice| +72=1|NormalVoice||HeadingLevel5Voice| +73=1|NormalVoice||HeadingLevel6Voice| +74=1|NormalVoice||| +75=1|NormalVoice||| +76=1|NormalVoice||| +77=1|NormalVoice||| +78=1|NormalVoice||| +79=1|NormalVoice||| +80=1|NormalVoice||| +81=1|NormalVoice||| +82=1|NormalVoice||| +83=1|NormalVoice||| +default=1|NormalVoice||| +[ControlState Behavior Table] +1=1|NormalVoice||| +2=1|NormalVoice||| +4=1|NormalVoice||| +8=1|NormalVoice||| +16=1|NormalVoice||| +32=1|NormalVoice||| +64=1|NormalVoice||| +128=1|NormalVoice||| +256=1|NormalVoice||| +512=1|NormalVoice||| +1024=1|NormalVoice||| +2048=1|NormalVoice||| +4096=1|NormalVoice||| +default=1|NormalVoice||| +[Information] +Description=special scheme for use with latex. diff --git a/latex_access/hungarian_speech.py b/latex_access/hungarian_speech.py new file mode 100644 index 0000000..da9624e --- /dev/null +++ b/latex_access/hungarian_speech.py @@ -0,0 +1,428 @@ +# -*- coding: utf8 -*- +# speech.py +# A part of the latex-access project at http://latex-access.sourceforge.net/ +# Author: Alastair Irving +# Modified by: Istvan Velegi +# Copyright (C) 2011 Alastair Irving/latex-access Contributors + +# This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; +# either version 2 of the License, or (at your option) any later version. +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU General Public License for more details. +# You should have received a copy of the GNU General Public License along with this program; if not, visit +# +'''Module to provide speech output for latex_access.''' + +import latex_access +from latex_access import get_arg +import re + +primes=re.compile(r"^\s*(\\p+rime\s*)+$") +argprimes=re.compile(r"^\s*\(.*\)$") +absertek =re.compile(r"\|([^\|]+)\|") +#norma =re.compile(r"\\|(.)\\|+") +sqrt_with_two_args =re.compile(r".*\\sqrt\[(.?)\]") + +#Define a list of words to use as denominators of simple fractions +denominators=[" per 0 "," per 1 "," ketted"," harmad"," negyed",u" ötöd"," hatod"," heted"," nyolcad"," kilenced"] + +class speech(latex_access.translator): + '''Speech translator class.''' + + def __init__(self): + self.handleBracketsAsPrime =False + self.abbrev_first_root_arg =False + latex_access.translator.__init__(self) + self.files.append("speech.table") + self.load_files() + + new_table={"\\cap":self.cap, "\\bigcap":self.cap, "\\binom":self.binom,"\\vec":self.vect,"\\underline":self.underline,"$":self.dollar,"^":self.super,"_":("",""),"\\pmod":("mod ",""),"\\widetilde":self.tilde,"\\tilde":self.tilde,"\\sqrt":self.sqrt,"\\frac":self.frac,"\\dfrac":self.frac,"\\ds":self.dsfrac,"\\int":self.integral,"\\dbint":self.dbintegral,"\\ddint":self.ddintegral,"\\oint":self.ointegral,"\\cup":self.union,"\\bigcup":self.union,"\\sum":self.sum,"\\prod":self.prod,"\\bf":("",""),"\\mathbf":("",""),"\\mathbb":("",""),"\\mathcal":("",""), "\\em":("",""), "\\it":("",""), "\\log":self.log,"\\ang":self.ang,"\\tag":self.tag,"\\hat":self.hat,"\\widehat":self.hat,"\\bar":("",u" felĂĽlvonás "),"\\overline":self.overline,"\\dot":("","pont"),"\\ddot":("","duplapont")} + for (k,v) in new_table.iteritems(): + self.table[k]=v + self.space=" " + + + def correct(self, inputstr): + inputstr =inputstr.replace("xy", "x y") + inputstr =inputstr.replace("yx", "y x") + inputstr =inputstr.replace("yy", "y y") + inputstr =inputstr.replace("ix", "i x") + inputstr =inputstr.replace("imx", "i m x") + inputstr =inputstr.replace("ikx", "i k x") + inputstr =inputstr.replace("isx", "i es x") + inputstr =inputstr.replace("inx", "i n x") + return inputstr + + def lowerSuffixParse(self, inputstr): + l1 =["1", "2", "4", "5", "7", "9", "x", "b", "c"] + l2 =["3", "6", "8", "y"] + if len(inputstr) ==0: + return u"-tĂłl " + if len(inputstr) >1 and inputstr.endswith(u"egyenlĹ‘ 0") or inputstr[:-1].isdigit() and inputstr[-2] ==u"0" and inputstr[-1] ==u"0" and inputstr !=u"1000": + return inputstr+u"-tĂłl " + if inputstr ==u"0": + return u" nullátĂłl " + if inputstr[-1].lower() in l1: + return inputstr+u"-tĹ‘l " + elif inputstr[-1].lower() in l2: + return inputstr +u"-tĂłl " + else: + if inputstr[-1].lower() ==u"a": + return inputstr[:-1] +inputstr[-1].lower().replace(u"a", u"átĂłl ") + if inputstr[-2:].lower() =="a ": + return inputstr[:-2] +inputstr[-2:].lower().replace(u"a ", u"átĂłl ") + return inputstr +u"-tĹ‘l " + + def upperSuffixParse(self, inputstr): + if inputstr.lower().endswith("a"): + return inputstr[:-1] +inputstr[-1].lower().replace(u"a", u"áig ") + elif inputstr[-2:] =="a ": + return inputstr[:-2] +inputstr[-2:].lower().replace(u"a ", u"áig ") + else: + return inputstr +u"-ig " + + def super(self,input,start): + '''Translate superscripts into speech. + Returns a touple with translated string and index of + first char after end of super.''' + + arg_with_minus =re.compile(r"-.?") + arg=get_arg(input,start) + #Handle squared and cubed as special cases + if arg[0] == "2": + translation=u" nĂ©gyzet " + elif arg[0]=="3": + translation=u" köb " + + elif len(arg[0]) <2 or arg_with_minus.match(arg[0]): + translation =u" ad %s, " % self.correct(self.translate(arg[0])) + + #Handle primes + elif primes.match(arg[0]): + if arg[0].count("p") ==1: + if arg[0].count("\\prime") ==1: + translation=u" vesszĹ‘ " + else: + translation=u" " +str(arg[0].count("\\prime")).replace("2", u"kĂ©t") +u" vesszĹ‘ " + elif arg[0].count("p") >1: + translation=u" " +str(self.correct(arg[0]).count("p")).replace("2", u"kĂ©t") +u" vesszĹ‘ " + + elif argprimes.match(arg[0]) and self.handleBracketsAsPrime: + translation =u" %s " % self.translate(self.correct(arg[0])) +u" vesszĹ‘ " + else: + translation = u" ad %s " % self.translate(self.correct(arg[0])) + return (translation, arg[1]) + + def sqrt(self,input,start): + '''Translates roots into speech. + + returns touple.''' + if sqrt_with_two_args.match(input): + first_arg =latex_access.get_optional_arg(input, start) + second_arg=get_arg(input, first_arg[1]) + + if self.abbrev_first_root_arg ==True: + if first_arg[0].isdigit() or len(first_arg[0]) ==1: + translation =denominators[int(first_arg[0])] +" " + elif first_arg[0] in ["x", "n"] and len(first_arg[0]) ==1: + translation =first_arg[0] +u"-ed " + elif first_arg[0] =="3": + translation =u" köb " + else: + translation =self.correct(self.translate(first_arg[0])) +u". " + + else: + if first_arg[0] =="3": + translation =u" köb " + elif first_arg[0].lower() =="n": + translation =u"n-edik " + elif first_arg[0] =="x": + translation ="x-edik " + else: + translation =self.correct(self.translate(first_arg[0])) +u". " + + if len(second_arg[0]) ==1: + translation +=u" gyök " +self.correct(self.translate(second_arg[0])) + else: + translation +=u" gyök alatt, "+self.correct(self.translate(second_arg[0])) +u", gyök zár " + return (translation, second_arg[1]) + + arg=get_arg(input, start) + if arg[0].isdigit() or len(arg[0])==1: + translation=u" gyök " +arg[0] + else: + translation=u" gyök alatt, " +self.correct(self.translate(arg[0])) +u", gyök zár" + return (translation,arg[1]) + + def norma(self, input, start): + m =absertek.match(input) + + if m is not None: + arg=get_arg("{"+m.group(1)+"}", 0) + if len(arg[0]) ==1: + output =self.translate(arg[0])+u" abszolĂşt " + return (output, arg[1]) + else: + output =u" abszolĂşt " +self.translate(arg[0]+u" abszolĂşt ") + return (output, arg[1]) + else: + arg =get_arg(input, start-1) + output =u" fĂĽggĹ‘leges " + return (output, arg[1]) + + + def frac(self,input,start): + '''Translate fractions into speech. + + Returns touple.''' + numerator=get_arg(input,start) + if numerator[1]1: + translation+="" + translation+=" " + else: + translation =" %s per %s " % (self.correct(numerator[0]), self.correct(denominator[0])) + else: + translation=u" tört, %s per %s, tört zár " % (self.translate(self.correct(numerator[0])), self.translate(self.correct(denominator[0]))) + return (translation,denominator[1]) + + def dsfrac(self,input,start): + arg=get_arg(input,start) + translation=u" tört "+self.correct(self.translate(arg[0])) +u" tört zár " + return (translation,arg[1]) + + def integral(self,input,start): + '''Translate integrals, including limits of integration. + Returns touple.''' + + (lower,upper,i)=latex_access.get_subsuper(input,start) + output =u"integrál " + if lower is not None and upper is not None and len(lower[0]) !=0 and len(upper[0]) !=0: + output +=self.lowerSuffixParse(self.translate(lower[0])) + output +=self.upperSuffixParse(self.translate(upper[0])) + else: + if lower is not None and len(lower[0]) !=0: + output +=""+self.correct(self.translate(lower[0]))+"" + return (output,i) + + def dbintegral(self,input,start): + '''Translate integrals, including limits of integration. + Returns touple.''' + output =u"kettĹ‘s integrál " + (lower,upper,i)=latex_access.get_subsuper(input,start) + if lower is not None and upper is not None and len(lower[0]) !=0 and len(upper[0]) !=0: + output +=self.lowerSuffixParse(self.translate(lower[0])) + output +=self.upperSuffixParse(self.translate(upper[0])) + else: + if lower is not None and len(lower[0]) !=0: + output +=""+self.correct(self.translate(lower[0]))+"" + return (output,i) + + def ddintegral(self,input,start): + '''Translate integrals, including limits of integration. + Returns touple.''' + + (lower,upper,i)=latex_access.get_subsuper(input,start) + output =u"hármas integrál " + if lower is not None and upper is not None and len(lower[0]) !=0 and len(upper[0]) !=0: + output +=self.lowerSuffixParse(self.translate(lower[0])) + output +=self.upperSuffixParse(self.translate(upper[0])) + else: + if lower is not None and len(lower[0]) !=0: + output +=""+self.correct(self.translate(lower[0]))+"" + return (output,i) + + def ointegral(self,input,start): + '''Translate integrals, including limits of integration. + Returns touple.''' + + (lower,upper,i)=latex_access.get_subsuper(input,start) + output =u"hurokintegrál " + if lower is not None and upper is not None and len(lower[0]) !=0 and len(upper[0]) !=0: + output +=self.lowerSuffixParse(self.translate(lower[0])) + output +=self.upperSuffixParse(self.translate(upper[0])) + elif lower is not None and len(lower[0]) !=0: + output +=""+self.correct(self.translate(lower[0]))+"" + + return (output,i) + + def sum(self,input,start): + '''Translate summas, including limits of summarization. + Returns touple.''' + input.replace("\\limits", "") + (lower,upper,i)=latex_access.get_subsuper(input,start) + output=u" szumma " + if lower is not None and upper is not None and len(lower[0]) !=0 and len(upper[0]) !=0: + output +=self.lowerSuffixParse(self.translate(lower[0])).replace(u"egyenlĹ‘", u"megy") + output +=self.upperSuffixParse(self.translate(upper[0])) + elif lower is not None and len(lower[0]) !=0: + output +=""+self.correct(self.translate(lower[0]))+"" + + return (output,i) + + def prod(self,input,start): + '''Translate products, including limits of producttion. + Returns touple.''' + input.replace("\\limits", "") + (lower,upper,i)=latex_access.get_subsuper(input,start) + output=u" produktum " + if lower is not None and upper is not None and len(lower[0]) !=0 and len(upper[0]) !=0: + output +=self.lowerSuffixParse(self.translate(lower[0])).replace(u"egyenlĹ‘", u"megy") + output +=self.upperSuffixParse(self.translate(upper[0])) + elif lower is not None and len(lower[0]) !=0: + output +=""+self.correct(self.translate(lower[0]))+"" + + return (output,i) + + def union(self,input,start): + '''Translate unions, including limits of unition. + Returns touple.''' + (lower,upper,i)=latex_access.get_subsuper(input,start) + output=u" uniĂł " + if lower is not None and upper is not None and len(lower[0]) !=0 and len(upper[0]) !=0: + output +=self.lowerSuffixParse(self.translate(lower[0])).replace(u"egyenlĹ‘", u"megy") + output +=self.upperSuffixParse(self.translate(upper[0])) + elif lower is not None and len(lower[0]) !=0: + output +=""+self.correct(self.translate(lower[0]))+"" + + return (output,i) + + def cap(self,input,start): + '''Translate intersections, including limits of intersection. + Returns touple.''' + (lower,upper,i)=latex_access.get_subsuper(input,start) + output=u" metszet " + if lower is not None and upper is not None and len(lower[0]) !=0 and len(upper[0]) !=0: + output +=self.lowerSuffixParse(self.translate(lower[0])).replace(u"egyenlĹ‘", u"megy") + output +=self.upperSuffixParse(self.translate(upper[0])) + elif lower is not None and len(lower[0]) !=0: + output +=""+self.correct(self.translate(lower[0]))+"" + + return (output,i) + + def tag(self,input,start): + '''Translate tags into speech. + + Returns a touple with translated string and index of + first char after end of tag.''' + + arg=get_arg(input,start) + translation=" tag left paren "+arg[0]+" right paren " + return (translation,arg[1]) + + def ang(self,input,start): + '''Translate angles into speech. + + Returns a touple with translated string and index of + first char after end of angle.''' + + translation = "" + counter = 0 + arg=get_arg(input,start) + if ';' in arg[0]: # we have mins possibly seconds too + for x in arg[0]: + if ';' == x: # we have mins/sec + counter=counter+1 + if counter == 1: + translation=translation+" degrees " + continue + elif counter == 2: + translation=translation+" minutes " + continue + elif counter == 3: + translation=translation+" seconds " + continue + translation=translation+x + if counter == 1: + translation=translation+" minutes" + elif counter == 2: + translation=translation+" seconds" + else: + translation=arg[0]+" degrees" + return (translation,arg[1]) + + def log(self,input,start): + '''Translate logs into speech. + We translate logs in the form \log_a(x) as + log base a of x + + If the log appears ambiguous, i.e. we can not reasonably + determine the base, we shall translate as just "log" followed by + any usual translation. + + Returns a touple with translated string and index of + first char after end of entire logarithm.''' + + + log=get_arg(input,start) + if len(log[0]) < 1 or log[0][0] != "_": # \log by itself + return (" log ", log[2]) # ignore the supposed command + + # Safe to assume log is of the form \log_a(x) + translation =u"" + base=get_arg(input, log[1]) + translation+=self.translate(base[0]) + translation+=u" alapĂş logaritmus " + + return (translation, base[1]) + + def underline(self,input,start): + arg=get_arg(input,start) + translation=self.translate(arg[0]) + return (translation,arg[1]) + + def overline(self,input,start): + arg=get_arg(input,start) + if arg[0].isdigit() or len(arg[0])==1: + translation=arg[0]+u" felĂĽlvonás " + else: + translation=u" felĂĽlvonás "+self.translate(self.correct(arg[0])) +u" felĂĽlvonás zár " + return (translation,arg[1]) + + def tilde(self,input,start): + arg=get_arg(input,start) + if arg[0].isdigit() or len(arg[0])==1: + translation=arg[0]+u" hullám " + else: + translation=u" hullám "+self.translate(self.correct(arg[0])) +u" hullám zár " + return (translation,arg[1]) + + def hat(self,input,start): + arg=get_arg(input,start) + if arg[0].isdigit() or len(arg[0])==1: + translation=arg[0]+u" kalap " + else: + translation=u" kalap "+self.translate(self.correct(arg[0])) +u" kalap zár " + return (translation,arg[1]) + + def vect(self,input,start): + arg=get_arg(input,start) + if arg[0].isdigit() or len(arg[0])==1: + translation=arg[0].replace("a", u"á") +u" vektor " + else: + translation=u" vektor, "+self.translate(self.correct(arg[0])) +u", vektor zár " + return (translation,arg[1]) + + def binom(self, input, start): + '''Translate binomials into speech. + Returns touple.''' + + arg_1=get_arg(input,start) + if arg_1[1] nagyobb * szorozva \times kereszt -\div osztva +\div per +\over per +/ per \pm pluszminusz \leq kisebb egyenlĹ‘ +\leqq kisebb egyenlĹ‘ \le kisebb egyenlĹ‘ \geq nagyobb egyenlĹ‘ \ge nagyobb egyenlĹ‘ +\geqq nagyobb egyenlĹ‘ \equiv ekvivalens \neq nem egyenlĹ‘ \ne nem egyenlĹ‘ \ll kisebb kisebb \gg nagyobb nagyobb -\prod produktum \pm pluszminusz \mp minuszplusz \leftrightarrow akkor Ă©s csak akkor ha @@ -27,122 +30,130 @@ \Leftrightarrow akkor Ă©s csak akkor ha \longrightarrow jobbranyĂ­l \longleftrightarrow akkor Ă©s csak akkor ha +\Longleftrightarrow akkor Ă©s csak akkor ha \wedge Ă©s \vee vagy \lnot nem \not nem +\neg nem \propto proportional to -\min min -\max max +\min min +\max max ; Trigonometrikus Ă©s hiperbolikus fĂĽggvĂ©nyek \tanh tangens hiperbolikusz \tan tangens +\arctan arkusz tangens \sinh szinusz hiperbolikusz \sin szinusz +\arcsin arkusz szinusz \cosh koszinusz hiperbolikusz \cos koszinusz +\arccos arkusz koszinusz ; Nagy görög betűk -\Alpha nagy alfa -\Beta nagy bĂ©ta -\Gamma nagy gamma -\Delta nagy delta -\Epsilon nagy epszilon -\Zeta nagy zeta -\Eta nagy Ă©ta -\Theta nagy teta +\Alpha nagy alfa +\Beta nagy bĂ©ta +\Gamma nagy gamma +\Delta nagy delta +\Epsilon nagy epszilon + +\Zeta nagy zeta +\Eta nagy Ă©ta +\Theta nagy teta \Iota nagy iota \Kappa nagy kappa -\Lambda nagy lambda +\Lambda nagy lambda \Mu nagy mű \Nu nagy nű \Xi nagy xĂ­ \Omicron nagy omikron \Pi nagy pĂ­ \Rho nagy rĂł -\Sigma nagy szigma -\Tau nagy tau -\Upsilon nagy upszilon -\Phi nagy fĂ­ +\Sigma nagy szigma +\Tau nagy tau +\Upsilon nagy upszilon +\Phi nagy fĂ­ \Psi nagy pszĂ­ -\Chi nagy khĂ­ -\Omega nagy omega +\Chi nagy khĂ­ +\Omega nagy omega ; kis görög betűk -\alpha alfa -\beta bĂ©ta -\gamma gamma -\delta delta -\epsilon epszilon -\zeta zeta -\eta Ă©ta -\theta teta +\alpha alfa +\beta bĂ©ta +\gamma gamma +\delta delta +\epsilon epszilon +\zeta zeta +\eta Ă©ta +\theta teta \iota iota \kappa kappa -\lambda lambda -\mu mű -\nu nű -\xi xĂ­ -\omicron omikron -\pi pĂ­ -\rho rĂł -\sigma szigma -\tau tau -\upsilon upszilon -\phi fĂ­ -\psi pszĂ­ -\chi khĂ­ -\omega omega - -\varpi pĂ­ -\varphi fĂ­ -\vartheta teta +\lambda lambda +\mu mű +\nu nű +\xi xĂ­ +\omicron omikron +\pi pĂ­ +\rho rĂł +\sigma szigma +\tau tau +\upsilon upszilon +\phi fĂ­ +\psi pszĂ­ +\chi khĂ­ +\omega omega +\varpi pĂ­ +\varphi fĂ­ +\vartheta teta +\varepsilon epszilon ; set theory -\bigcap metszet -\bigcup uniĂł -\setminus set minus -\cap metszet +\setminus kĂĽlönbsĂ©g \triangleleft normál alcsoport -\therefore ezĂ©rt +\therefore ezĂ©rt \supseteq szuperhalmaz vagy egyenlĹ‘ -\supset szuperhalmaz -\subseteq rĂ©szhalmaza vagy egyenlĹ‘ +\supset szuperhalmaz +\subseteq rĂ©szhalmaza vagy egyenlĹ‘ \subset rĂ©szhalmaza -\rmint belsĹ‘ pontok +\rmint interior \subs rĂ©sze +\setminus kĂĽlönbsĂ©g \in eleme \notin nem eleme \ni nem eleme \forall minden \exists lĂ©tezik -\emptyset ĂĽres halmaz -\cup uniĂł +\emptyset ĂĽres halmaz \lim limesz -\{ kezdĹ‘kapcsos -\} vĂ©gkapcsos +\{ kezdĹ‘kapcsos +\} vĂ©gkapcsos -; Standard latex parancsok jobb olvasáshoz: +; Standard latex parancsok gördĂĽlĂ©kenyebb olvasáshoz: \cdot szorozva -\cdots pont pont pont -\right -\quad -\qquad -\left +\cdots pont pont pont +\vdots pont pont pont +\right +\quad +\qquad +\left \ldots pont pont pont \dots pont pont pont -\; -\, -\! +\; +\, +\! +\rm \textbackslash \ -\dsp +\dsp +\Dsp +\mathop +\limits \textdegree fok ; calculus -\partial parciális -\nabla nabla +\partial parciális +\nabla nabla Speciális karakterek @@ -152,7 +163,21 @@ Speciális karakterek ValĂłszĂ­nűsĂ©g Ă©s permutáciĂł \Pr valĂłszĂ­nűsĂ©g ! faktoriális -| fĂĽggĹ‘leges +\choose alatt +\Choose alatt + + +EgyĂ©b jelölĂ©sek ' vesszĹ‘ \Vert norma -\vert norma \ No newline at end of file +\vert norma +| fĂĽggĹ‘leges +\haf f kalap +\clF fourier transzformált +\lceil felfelĂ© kerekĂ­t +\rceil kerekĂ­tĂ©s zár +\exp e ad +\ovz z konjugált + +;list item operators: +\item item \ No newline at end of file diff --git a/latex_access/speech.py b/latex_access/speech.py index 37be8b2..3580e41 100644 --- a/latex_access/speech.py +++ b/latex_access/speech.py @@ -1,174 +1,174 @@ -# speech.py -# A part of the latex-access project at http://latex-access.sourceforge.net/ -# Author: Alastair Irving -# Copyright (C) 2011 Alastair Irving/latex-access Contributors -# -# This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; -# either version 2 of the License, or (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -# See the GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along with this program; if not, visit -# -'''Module to provide speech output for latex_access.''' - - -import latex_access -from latex_access import get_arg - -#Define a list of words to use as denominators of simple fractions -denominators=[" over zero"," over1 "," half"," third"," quarter"," fifth"," sixth"," seventh"," eight"," ninth"] - -class speech(latex_access.translator): - '''Speech translator class.''' - def __init__(self): - latex_access.translator.__init__(self) - self.files.append("speech.table") - self.load_files() - new_table={"^":self.super,"_":("",""),"\\pmod":("mod ",""),"\\sqrt":self.sqrt,"\\frac":self.frac,"\\tfrac":self.frac,"\\dfrac":self.frac,"\\int":self.integral,"\\mathbf":("",""),"\\mathbb":("",""),"\\mathcal":("",""), - "\\log":self.log,"\\ang":self.ang,"\\tag":self.tag,"\\hat":("","hat"),"\\widehat":("","hat"),"\\bar":("","bar"),"\\overline":("","bar"),"\\dot":("","dot"),"\\ddot":("","double dot")} - - for (k,v) in new_table.iteritems(): - self.table[k]=v - self.space=" " - - - - - - def super(self,input,start): - '''Translate superscripts into speech. - - Returns a touple with translated string and index of - first char after end of super.''' - arg=get_arg(input,start) - #Handle squared and cubed as special cases - if arg[0] == "2": - translation=" squared " - elif arg[0]=="3": - translation=" cubed " - #Handle primes - elif latex_access.primes.match(arg[0]): - translation=" prime "*arg[0].count("\\prime") - else: - translation = " to the %s end super " % self.translate(arg[0]) - return (translation,arg[1]) - - - def sqrt(self,input,start): - '''Translates squareroots into speech. - - returns touple.''' - arg=get_arg(input,start) - if arg[0].isdigit() or len(arg[0])==1: - translation=" root "+arg[0] - else: - translation=" begin root "+self.translate(arg[0])+" end root " - return (translation,arg[1]) - - - - def frac(self,input,start): - '''Translate fractions into speech. - - Returns touple.''' - numerator=get_arg(input,start) - if numerator[1]1: - translation+="s" - translation+=" " - else: - translation =" %s over %s " % (numerator[0], denominator[0]) - else: - translation=" begin frac %s over %s end frac " % (self.translate(numerator[0]), self.translate(denominator[0])) - return (translation,denominator[1]) - - def integral(self,input,start): - '''Translate integrals, including limits of integration. - - Returns touple.''' - (lower,upper,i)=latex_access.get_subsuper(input,start) - output=" integral " - if lower is not None: - output+="from " - output+=self.translate(lower[0]) - if upper is not None: - output+=" to " - output+=self.translate(upper[0]) - output+=" of " - return (output,i) - - def tag(self,input,start): - '''Translate tags into speech. - - Returns a touple with translated string and index of - first char after end of tag.''' - - arg=get_arg(input,start) - translation=" tag left paren "+arg[0]+" right paren " - return (translation,arg[1]) - - def ang(self,input,start): - '''Translate angles into speech. - - Returns a touple with translated string and index of - first char after end of angle.''' - - translation = "" - counter = 0 - arg=get_arg(input,start) - if ';' in arg[0]: # we have mins possibly seconds too - for x in arg[0]: - if ';' == x: # we have mins/sec - counter=counter+1 - if counter == 1: - translation=translation+" degrees " - continue - elif counter == 2: - translation=translation+" minutes " - continue - elif counter == 3: - translation=translation+" seconds " - continue - translation=translation+x - if counter == 1: - translation=translation+" minutes" - elif counter == 2: - translation=translation+" seconds" - else: - translation=arg[0]+" degrees" - return (translation,arg[1]) - - def log(self,input,start): - '''Translate logs into speech. - - We translate logs in the form \log_a(x) as - log base a of x - - If the log appaears ambiguous, i.e. we can not reasonably - determine the base, we shall translate as just "log" followed by - any usual translation. - - Returns a touple with translated string and index of - first char after end of entire logarithm.''' - - log=get_arg(input,start) - translation=" log " - if len(log[0]) < 1 or log[0][0] != "_": # \log by itself - return (translation, log[2]) # ignore the supposed command - -# Safe to assume log is of the form \log_a(x) - translation+="base " - base=get_arg(input, log[1]) - translation+=self.translate (base[0]) - translation+=" of " - return (translation, base[1]) - +# speech.py +# A part of the latex-access project at http://latex-access.sourceforge.net/ +# Author: Alastair Irving +# Copyright (C) 2011 Alastair Irving/latex-access Contributors +# +# This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; +# either version 2 of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with this program; if not, visit +# +'''Module to provide speech output for latex_access.''' + + +import latex_access +from latex_access import get_arg + +#Define a list of words to use as denominators of simple fractions +denominators=[" over zero"," over1 "," half"," third"," quarter"," fifth"," sixth"," seventh"," eight"," ninth"] + +class speech(latex_access.translator): + '''Speech translator class.''' + def __init__(self): + latex_access.translator.__init__(self) + self.files.append("speech.table") + self.load_files() + new_table={"^":self.super,"_":("",""),"\\pmod":("mod ",""),"\\sqrt":self.sqrt,"\\frac":self.frac,"\\tfrac":self.frac,"\\dfrac":self.frac,"\\int":self.integral,"\\mathbf":("",""),"\\mathbb":("",""),"\\mathcal":("",""), + "\\log":self.log,"\\ang":self.ang,"\\tag":self.tag,"\\hat":("","hat"),"\\widehat":("","hat"),"\\bar":("","bar"),"\\overline":("","bar"),"\\dot":("","dot"),"\\ddot":("","double dot")} + + for (k,v) in new_table.iteritems(): + self.table[k]=v + self.space=" " + + + + + + def super(self,input,start): + '''Translate superscripts into speech. + + Returns a touple with translated string and index of + first char after end of super.''' + arg=get_arg(input,start) + #Handle squared and cubed as special cases + if arg[0] == "2": + translation=" squared " + elif arg[0]=="3": + translation=" cubed " + #Handle primes + elif latex_access.primes.match(arg[0]): + translation=" prime "*arg[0].count("\\prime") + else: + translation = " to the %s end super " % self.translate(arg[0]) + return (translation,arg[1]) + + + def sqrt(self,input,start): + '''Translates squareroots into speech. + + returns touple.''' + arg=get_arg(input,start) + if arg[0].isdigit() or len(arg[0])==1: + translation=" root "+arg[0] + else: + translation=" begin root "+self.translate(arg[0])+" end root " + return (translation,arg[1]) + + + + def frac(self,input,start): + '''Translate fractions into speech. + + Returns touple.''' + numerator=get_arg(input,start) + if numerator[1]1: + translation+="s" + translation+=" " + else: + translation =" %s over %s " % (numerator[0], denominator[0]) + else: + translation=" begin frac %s over %s end frac " % (self.translate(numerator[0]), self.translate(denominator[0])) + return (translation,denominator[1]) + + def integral(self,input,start): + '''Translate integrals, including limits of integration. + + Returns touple.''' + (lower,upper,i)=latex_access.get_subsuper(input,start) + output=" integral " + if lower is not None: + output+="from " + output+=self.translate(lower[0]) + if upper is not None: + output+=" to " + output+=self.translate(upper[0]) + output+=" of " + return (output,i) + + def tag(self,input,start): + '''Translate tags into speech. + + Returns a touple with translated string and index of + first char after end of tag.''' + + arg=get_arg(input,start) + translation=" tag left paren "+arg[0]+" right paren " + return (translation,arg[1]) + + def ang(self,input,start): + '''Translate angles into speech. + + Returns a touple with translated string and index of + first char after end of angle.''' + + translation = "" + counter = 0 + arg=get_arg(input,start) + if ';' in arg[0]: # we have mins possibly seconds too + for x in arg[0]: + if ';' == x: # we have mins/sec + counter=counter+1 + if counter == 1: + translation=translation+" degrees " + continue + elif counter == 2: + translation=translation+" minutes " + continue + elif counter == 3: + translation=translation+" seconds " + continue + translation=translation+x + if counter == 1: + translation=translation+" minutes" + elif counter == 2: + translation=translation+" seconds" + else: + translation=arg[0]+" degrees" + return (translation,arg[1]) + + def log(self,input,start): + '''Translate logs into speech. + + We translate logs in the form \log_a(x) as + log base a of x + + If the log appaears ambiguous, i.e. we can not reasonably + determine the base, we shall translate as just "log" followed by + any usual translation. + + Returns a touple with translated string and index of + first char after end of entire logarithm.''' + + log=get_arg(input,start) + translation=" log " + if len(log[0]) < 1 or log[0][0] != "_": # \log by itself + return (translation, log[2]) # ignore the supposed command + +# Safe to assume log is of the form \log_a(x) + translation+="base " + base=get_arg(input, log[1]) + translation+=self.translate (base[0]) + translation+=" of " + return (translation, base[1]) + diff --git a/latex_access/speech_modified.py b/latex_access/speech_modified.py new file mode 100644 index 0000000..d709405 --- /dev/null +++ b/latex_access/speech_modified.py @@ -0,0 +1,397 @@ +# -*- coding: utf8 -*- +# speech.py +# A part of the latex-access project at http://latex-access.sourceforge.net/ +# Author: Alastair Irving +# Modified by: Istvan Velegi +# Copyright (C) 2011 Alastair Irving/latex-access Contributors +# +# This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; +# either version 2 of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with this program; if not, visit +# +'''Module to provide speech output for latex_access.''' + + +import latex_access +from latex_access import get_arg +import re + +#Define a list of words to use as denominators of simple fractions +denominators=[" over zero"," over1 "," half"," third"," quarter"," fifth"," sixth"," seventh"," eight"," ninth"] + +sqrt_with_two_args =re.compile(r".*\\sqrt\[(.?)\]") + +class speech(latex_access.translator): + '''Speech translator class.''' + def __init__(self): + latex_access.translator.__init__(self) + self.files.append("speech.table") + self.load_files() + new_table ={"\\cap":self.cap,"\\bigcap":self.cap, "\\ln":self.ln,"\\binom":self.binom,"\\vec":self.vect,"^":self.super,"_":("",""),"\\pmod":("mod ",""), + "\\sqrt":self.sqrt,"\\frac":self.frac,"\\tfrac":self.frac,"\\dfrac":self.frac, + "\\int":self.integral,"\\dbint":self.dbintegral,"\\ddint":self.ddintegral,"\\oint":self.ointegral, + "\\it":("",""),"\\bf":("",""),"\\mathbf":("",""),"\\mathbb":("",""), + "\\mathcal":("",""),"\\log":self.log,"\\ang":self.ang, + "\\tag":self.tag,"\\hat":("","hat"),"\\widehat":("","hat"),"\\bar":("","bar"), + "\\overline":("","bar"),"\\dot":("","dot"),"\\ddot":("","double dot"),"\\sum":self.sum,"\\prod":self.prod,"\\cup":self.union,"\\bigcup":self.union} + + for (k,v) in new_table.iteritems(): + self.table[k]=v + self.space=" " + + sqrt_with_two_args =re.compile(r".*\\sqrt\[(.*)\]+.*") + + def correct(self, inputstr): + inputstr =inputstr.replace("xy", "x y") + inputstr =inputstr.replace("yx", "y x") + inputstr =inputstr.replace("yy", "y y") + inputstr =inputstr.replace("ix", "i x") + inputstr =inputstr.replace("imx", "i m x") + inputstr =inputstr.replace("ikx", "i k x") + inputstr =inputstr.replace("isx", "i es x") + inputstr =inputstr.replace("inx", "i n x") + return inputstr + + + def super(self,input,start): + '''Translate superscripts into speech. + + Returns a touple with translated string and index of + first char after end of super.''' + + arg_with_minus =re.compile(r"-.?") + arg=get_arg(input,start) + #Handle squared and cubed as special cases + if arg[0] == "2": + translation=" squared " + elif arg[0]=="3": + translation=" cubed " + #Handle primes + elif latex_access.primes.match(arg[0]): + translation=" prime "*arg[0].count("\\prime") + else: + translation = " to the %s " % self.correct(self.translate(arg[0])) + return (translation,arg[1]) + + def sqrt(self,input,start): + '''Translates roots into speech. + returns touple.''' + + if self.sqrt_with_two_args.match(input): + first_arg =latex_access.get_optional_arg(input, start) + second_arg=get_arg(input, first_arg[1]) + + if first_arg[0] =="2": + translation =u" square " + elif first_arg[0] =="3": + translation =u" cube " + elif first_arg[0].lower() =="n": + translation =u"enth " + elif first_arg[0].lower() =="x": + translation =u"exth " + elif first_arg[0] =="": + translation =u"" + else: + translation =first_arg[0] +u"th " + + if len(second_arg[0]) ==1: + translation +=u"root " +self.correct(self.translate(second_arg[0])) + else: + translation +=u"root of " +self.correct(self.translate(second_arg[0])) + translation +=u" end root " + return (translation,second_arg[1]) + + arg=get_arg(input,start) + if arg[0].isdigit() or len(arg[0])==1: + translation =u" root " +arg[0] +u" " + else: + translation =u" root of " +self.correct(self.translate(arg[0])) +u" end root " + return (translation,arg[1]) + + def frac(self,input,start): + '''Translate fractions into speech. + + Returns touple.''' + numerator=get_arg(input,start) + if numerator[1]1: + translation+="s" + translation+=" " + else: + translation =" %s over %s " % (numerator[0], denominator[0]) + else: + translation=" begin frac, %s over %s, end frac " % (self.translate(numerator[0]), self.translate(denominator[0])) + return (translation,denominator[1]) + + def dsfrac(self,input,start): + arg=get_arg(input,start) + translation=u" begin frac "+self.correct(self.translate(arg[0])) +u" end frac " + return (translation,arg[1]) + + def integral(self,input,start): + '''Translate integrals, including limits of integration. + Returns touple.''' + + (lower,upper,i)=latex_access.get_subsuper(input,start) + output =u" integral " + + # Statement to prevent the translator from empty boundaries: + if lower is not None and upper is not None and len(lower[0]) !=0 and len(upper[0]) !=0: + output +=" from " + output +=self.correct(self.translate(lower[0])) + output +=" to " + output +=self.correct(self.translate(upper[0])) + output +=" of " + elif lower is not None and len(lower[0]) !=0: + output +=""+self.correct(self.translate(lower[0]))+"" + return (output,i) + + def dbintegral(self,input,start): + '''Translate double integrals, including limits of integration. + Returns touple.''' + + (lower,upper,i)=latex_access.get_subsuper(input,start) + output =u" double integral " + + # Statement to prevent the translator from empty boundaries: + if lower is not None and upper is not None and len(lower[0]) !=0 and len(upper[0]) !=0: + output +=" from " + output +=self.correct(self.translate(lower[0])) + output +=" to " + output +=self.correct(self.translate(upper[0])) + output +=" of " + elif lower is not None and len(lower[0]) !=0: + output +=""+self.correct(self.translate(lower[0]))+"" + return (output,i) + + + def ddintegral(self,input,start): + '''Translate triple integrals, including limits of integration. + Returns touple.''' + + (lower,upper,i)=latex_access.get_subsuper(input,start) + output =u" triple integral " + + # Statement to prevent the translator from empty boundaries: + if lower is not None and upper is not None and len(lower[0]) !=0 and len(upper[0]) !=0: + output +=" from " + output +=self.correct(self.translate(lower[0])) + output +=" to " + output +=self.correct(self.translate(upper[0])) + output +=" of " + elif lower is not None and len(lower[0]) !=0: + output +=""+self.correct(self.translate(lower[0]))+"" + return (output,i) + + def ointegral(self,input,start): + '''Translate double integrals, including limits of integration. + Returns touple.''' + + (lower,upper,i)=latex_access.get_subsuper(input,start) + output =u" loop integral " + + # Statement to prevent the translator from empty boundaries: + if lower is not None and upper is not None and len(lower[0]) !=0 and len(upper[0]) !=0: + output +=" from " + output +=self.correct(self.translate(lower[0])) + output +=" to " + output +=self.correct(self.translate(upper[0])) + output +=" of " + elif lower is not None and len(lower[0]) !=0: + output +=""+self.correct(self.translate(lower[0]))+"" + return (output,i) + + def sum(self,input,start): + '''Translate summas, including limits of summarization. + Returns touple.''' + + (lower,upper,i)=latex_access.get_subsuper(input,start) + output =u" sum " + + # Statement to prevent the translator from empty boundaries: + if lower is not None and upper is not None and len(lower[0]) !=0 and len(upper[0]) !=0: + output +=" where " + output +=self.correct(self.translate(lower[0])).replace("equals"," goes from ") + output +=" to " + output +=self.correct(self.translate(upper[0])) + output +=" of " + elif lower is not None and len(lower[0]) !=0: + output +=""+self.correct(self.translate(lower[0]))+"" + return (output,i) + + def prod(self,input,start): + '''Translate products, including limits of production. + Returns touple.''' + + (lower,upper,i)=latex_access.get_subsuper(input,start) + output =u" product " + + # Statement to prevent the translator from empty boundaries: + if lower is not None and upper is not None and len(lower[0]) !=0 and len(upper[0]) !=0: + output +=" where " + output +=self.correct(self.translate(lower[0])).replace("equals"," goes from ") + output +=" to " + output +=self.correct(self.translate(upper[0])) + output +=" of " + elif lower is not None and len(lower[0]) !=0: + output +=""+self.correct(self.translate(lower[0]))+"" + return (output,i) + + def union(self,input,start): + '''Translate unions, including limits of unition. + Returns touple.''' + + (lower,upper,i)=latex_access.get_subsuper(input,start) + output =u" union " + + # Statement to prevent the translator from empty boundaries: + if lower is not None and upper is not None and len(lower[0]) !=0 and len(upper[0]) !=0: + output +=" where " + output +=self.correct(self.translate(lower[0])).replace("equals"," goes from ") + output +=" to " + output +=self.correct(self.translate(upper[0])) + output +=" of " + elif lower is not None and len(lower[0]) !=0: + output +=""+self.correct(self.translate(lower[0]))+"" + return (output,i) + + def cap(self,input,start): + '''Translate intersections, including limits of intersection. + Returns touple.''' + (lower,upper,i)=latex_access.get_subsuper(input,start) + output=u" intersection " + # Statement to prevent the translator from empty boundaries: + if lower is not None and upper is not None and len(lower[0]) !=0 and len(upper[0]) !=0: + output +=" where " + output +=self.correct(self.translate(lower[0])).replace(u"equals", u" goes from ") + output +=u" to " + output +=self.correct(self.translate(upper[0])) + output+=u" of " + elif lower is not None and len(lower[0]) !=0: + output +=""+self.correct(self.translate(lower[0]))+"" + + return (output,i) + + + def tag(self,input,start): + '''Translate tags into speech. + + Returns a touple with translated string and index of + first char after end of tag.''' + + arg=get_arg(input,start) + translation=" tag left paren "+arg[0]+" right paren " + return (translation,arg[1]) + + def ang(self,input,start): + '''Translate angles into speech. + + Returns a touple with translated string and index of + first char after end of angle.''' + + translation = "" + counter = 0 + arg=get_arg(input,start) + if ';' in arg[0]: # we have mins possibly seconds too + for x in arg[0]: + if ';' == x: # we have mins/sec + counter=counter+1 + if counter == 1: + translation=translation+" degrees " + continue + elif counter == 2: + translation=translation+" minutes " + continue + elif counter == 3: + translation=translation+" seconds " + continue + translation=translation+x + if counter == 1: + translation=translation+" minutes" + elif counter == 2: + translation=translation+" seconds" + else: + translation=arg[0]+" degrees" + return (translation,arg[1]) + + def log(self,input,start): + '''Translate logs into speech. + + We translate logs in the form \log_a(x) as + log base a of x + + If the log appears ambiguous, i.e. we can not reasonably + determine the base, we shall translate as just "log" followed by + any usual translation. + + Returns a touple with translated string and index of + first char after end of entire logarithm.''' + + log=get_arg(input,start) + translation=" log " + if len(log[0]) < 1 or log[0][0] != "_": # \log by itself + return (translation, log[2]) # ignore the supposed command + +# Safe to assume log is of the form \log_a(x) + translation+="base " + base=get_arg(input, log[1]) + translation+=self.translate (base[0]) + translation+=" of " + return (translation, base[1]) + + def vect(self,input,start): + arg=get_arg(input,start) + if arg[0].isdigit() or len(arg[0])==1: + translation=arg[0] +u" vector " + else: + translation =u" vector " +self.correct(self.translate(arg[0])) +u" end vector " + return (translation,arg[1]) + + def binom(self, input, start): + '''Translate binomials into speech. + Returns touple.''' + + arg_1=get_arg(input,start) + if arg_1[1] greater than +\times times +\div divided by +\pm plus or minus +\leq less than or equal to +\le less than or equal to +\geq greater than or equal to +\ge greater than or equal to +\equiv equiv +\approx approximately equal to +\simeq similar or equal to +\sim similar +\neq not equals +\ne not equals +\ll less than less than +\gg greater than greater than +\sum sum +\pm plus or minus +\mp minus or plus +\leftrightarrow if and only if +\Rightarrow goes to +\rightarrow goes to +\to goes to +\Leftrightarrow if and only if +\longrightarrow goes to +\longleftrightarrow if and only if +\wedge and +\vee or +\lnot not +\not not +\neg not +\propto proportional to +\min min +\max max +\vert vert +\lfloor left floor +\rfloor right floor + +; trigonometric and hyperbolic functions +\tanh thann +\tan tan +\arctan arc tan +\sinh shine +\sin sine +\arcsin arc sine +\cosh cosh +\cos coz +\arccos arc coz + +; capital greek letters +\Alpha cap alpha +\Beta cap beta +\Gamma cap gamma +\Delta cap delta +\Epsilon cap epsilon +\Zeta cap zeta +\Eta cap eta +\Theta cap theta +\Iota cap iota +\Kappa cap kappa +\Lambda cap lambda +\Mu cap mu +\Nu cap nu +\Xi cap xi +\Omicron cap omicron +\Pi cap pi +\Rho cap rho +\Sigma cap sigma +\Tau cap tau +\Upsilon cap upsilon +\Phi cap phi +\Psi cap psi +\Chi cap chi +\Omega cap omega + +; small greek letters +\alpha alpha +\beta beta +\gamma gamma +\delta delta +\epsilon epsilon +\zeta zeta +\eta eta +\theta theta +\iota iota +\kappa kappa +\lambda lambda +\mu mu +\nu nu +\xi xi +\omicron omicron +\pi pi +\varpi var pi +\rho rho +\sigma sigma +\tau tau +\upsilon upsilon +\phi phi +\psi psi +\chi chi +\omega omega + +\varphi var phi +\vartheta var theta +\varepsilon var epsilon + + +; set theory +\setminus complement +\triangleleft normal subgroup +\therefore therefore +\supseteq superset or equal to +\supset superset +\subseteq subset or equal to +\subset subset +\in in +\notin not in +\ni not in +\forall for all +\exists there exists +\emptyset empty set +\lim limit +\{ open brace +\} close brace + +; standard LaTeX commands for better reading +\cdot dot +\cdots dot dot dot +\right +\quad +\qquad +\left +\ldots dot dot dot +\dots dot dot dot +\; +\, +\! +\: +\\limits + +\textbackslash \ +\textdegree degrees + +; calculus +\partial partial +\nabla nabla + +; special characters +\infty infinity +\perp perpendicular + +; Probability and permutations +\Pr probability of +\choose choose +\Choose choose + +;list item operators: +\item bullet + diff --git a/test.tex b/test.tex index 1befab2..a4f33a2 100644 --- a/test.tex +++ b/test.tex @@ -1,5 +1,6 @@ \documentclass[12pt]{article} \newcommand{\Srf}{\sqrt{5}} +q \begin{document} LaTeX Access test file: