@@ -313,7 +313,24 @@ def script_rawdataToClip(self, gesture: KeyboardInputGesture):
313313 ) # copy will fix up name spacing
314314 elif self .init_mathml != "" :
315315 mathml = self .init_mathml
316- self ._copyToClipAsMathML (mathml )
316+ copy_as = "mathml"
317+ try :
318+ copy_as = libmathcat .GetPreference ("CopyAs" ).lower ()
319+ match copy_as :
320+ case "mathml" | "latex" | "asciimath" :
321+ pass
322+ case _:
323+ copy_as = "mathml"
324+ except Exception as e :
325+ log .error (f"Not able to get 'CopyAs' preference: { e } " )
326+
327+ mathml = self ._wrapMathMLForClipBoard (mathml )
328+ if copy_as != "mathml" :
329+ saved_braille_code : str = libmathcat .GetPreference ("BrailleCode" )
330+ libmathcat .SetPreference ("BrailleCode" , "LaTeX" if copy_as == "latex" else "ASCIIMath" )
331+ mathml = libmathcat .GetNavigationBraille ()
332+ libmathcat .SetPreference ("BrailleCode" , saved_braille_code )
333+ self ._copyToClipAsMathML (mathml , copy_as == "mathml" )
317334 # Translators: copy to clipboard
318335 ui .message (_ ("copy" ))
319336 except Exception as e :
@@ -337,7 +354,7 @@ def _wrapMathMLForClipBoard(self, text: str) -> str:
337354 )
338355 return mathml_with_ns
339356
340- def _copyToClipAsMathML (self , text : str , notify : Optional [bool ] = False ) -> bool :
357+ def _copyToClipAsMathML (self , text : str , is_mathml : bool , notify : Optional [bool ] = False ) -> bool :
341358 """Copies the given text to the windows clipboard.
342359 @returns: True if it succeeds, False otherwise.
343360 @param text: the text which will be copied to the clipboard
@@ -350,9 +367,9 @@ def _copyToClipAsMathML(self, text: str, notify: Optional[bool] = False) -> bool
350367 try :
351368 with winUser .openClipboard (gui .mainFrame .Handle ):
352369 winUser .emptyClipboard ()
353- text = self . _wrapMathMLForClipBoard ( text )
354- self ._setClipboardData (self .CF_MathML , '<?xml version="1.0"?>' + text )
355- self ._setClipboardData (self .CF_MathML_Presentation , '<?xml version="1.0"?>' + text )
370+ if is_mathml :
371+ self ._setClipboardData (self .CF_MathML , '<?xml version="1.0"?>' + text )
372+ self ._setClipboardData (self .CF_MathML_Presentation , '<?xml version="1.0"?>' + text )
356373 self ._setClipboardData (winUser .CF_UNICODETEXT , text )
357374 got = getClipData ()
358375 except OSError :
@@ -449,7 +466,7 @@ def _add_sounds(self):
449466 try :
450467 return libmathcat .GetPreference ("SpeechSound" ) != "None"
451468 except Exception as e :
452- print (f"An exception occurred: { e } " )
469+ log . error (f"An exception occurred: { e } " )
453470 return False
454471
455472 def getBrailleForMathMl (self , mathml : str ):
0 commit comments