/usr/lib/libreoffice/share/extensions/DmathsAddon/CmathOOo/mImportFromLaTeX.xba is in libreoffice-dmaths 3.4+dfsg1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 | <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="mImportFromLaTeX" script:language="StarBasic">'***** BASIC *****
'CmathOOo
'Copyright (C) 2006 Christophe devalland
'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, write to the Free Software
'Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
option explicit
Sub Main
' PasteFromLatex
'stop
'ImportLatexFile
InitVariablesLaTeX2OOo
stop
dim oDocLatex as object, oDocOOo as object
dim oCurseurLatex as object
dim oCurseurDebut as object, oCurseurFin as object
dim sTexteLatex as string
oDocLatex=ThisComponent
bModeTexte=False
'oDocLatex est le document contenant le texte Latex
oDocOOo = StarDesktop.loadComponentFromURL( "private:factory/swriter", "_blank", 0,Array( MakePropertyValue( "Hidden", false) ) )
bModeTexte=False
oCurseurLatex=oDocLatex.text.createTextCursor
oCurseurLatex.gotoEnd(true)
sTexteLatex=SubstitutionsLatexAvantTraitement(oCurseurLatex.string)
' msgbox(oCurseurLatex.string)
DocLatex2OOo(oDocLatex, oDocOOo, sTexteLatex)
' oDocOOo.close( True )
End Sub
sub PasteFromLatex
dim oDocLatex as object, oDocOOo as object
dim oCurseurLatex as object
dim oCurseurDebut as object, oCurseurFin as object
dim sTexteLatex as string
' dim a as object
InitVariablesLaTeX2OOo
oDocOOo=ThisComponent
bModeTexte=False
'oDocLatex est le document contenant le texte Latex
oDocLatex = StarDesktop.loadComponentFromURL( "private:factory/swriter", "_blank", 0,Array( MakePropertyValue( "Hidden", false) ) )
oDocLatex.CurrentController.Frame.ContainerWindow.Visible=False
' le texte est dans le presse-papier
ClipboardPaste( oDocLatex )
' sélectionner tout le document
oCurseurLatex=oDocLatex.text.createTextCursor
oCurseurLatex.gotoEnd(true)
' oCurseurDebut=oDocLatex.text.createTextCursorByRange(oCurseurLatex.getStart())
' oCurseurFin=oDocLatex.text.createTextCursorByRange(oCurseurLatex.getEnd())
' oCurseurLatex.collapseToStart
'conversion
' DocLatex2OOo(oDocLatex, oDocOOo, oCurseurDebut, oCurseurFin)
sTexteLatex=oCurseurLatex.string
TraduitNewCommand(sTexteLatex)
sTexteLatex=SubstitutionsLatexAvantTraitement(sTexteLatex)
oDocLatex.close( True )
DocLatex2OOo(oDocOOo, sTexteLatex)
end sub
sub ImportLatexFile
dim oDocLatex as object, oDocOOo as object
' dim oCurseurLatex as object
dim oFP as object, slesFichiers() as string, sFichier as string
dim oCurseurDebut as object, oCurseurFin as object, oCurseurLatex as object
dim sTexteLatex as string
dim propFich(2) as New com.sun.star.beans.PropertyValue
dim i as long, j as long
dim a as object
InitVariablesLaTeX2OOo
oDocOOo=ThisComponent
bModeTexte=False
'oDocLatex est le document contenant le texte Latex
oFP=CreateUnoService("com.sun.star.ui.dialogs.FilePicker")
With oFP
' .DisplayDirectory =
.appendFilter("Sources Latex","*.tex")
.appendFilter("Tous documents","*.*")
.CurrentFilter("Sources Latex")
if .execute=com.sun.star.ui.dialogs.ExecutableDialogResults.OK then
slesFichiers=.Files
propFich(0).Name="FilterName"
propFich(0).Value="Text (encoded)"
propFich(1).Name="FilterOptions"
propFich(1).Value="ISO_8859_1" 'remplace Latin1
propFich(2).Name="Hidden"
propFich(2).Value=false
oDocLatex = StarDesktop.loadComponentFromURL( slesFichiers(0), "_blank", 0,propFich())
.dispose
oDocLatex.CurrentController.Frame.ContainerWindow.Visible=False
' rechercher \begin{document}
oCurseurLatex=oDocLatex.text.createTextCursor
oCurseurLatex.gotoEnd(true)
sTexteLatex=oCurseurLatex.string
TraduitNewCommand(sTexteLatex)
' oDocOOo.Text.insertString(oDocOOo.text.createTextCursor,sTexteLatex,false)
' à enlever :
oDocLatex.close( True )
' stop
' oCurseurDebut=oDocLatex.text.createTextCursor
' oCurseurFin=oDocLatex.text.createTextCursor
'
' oCurseurDebut.gotoRange(oTrouveExpression(oDocLatex, oCurseurLatex, "\begin{document}").start,false)
' oCurseurDebut.goRight(len("\begin{document}"),false)
' oCurseurFin.gotoRange(oTrouveExpression(oDocLatex, oCurseurLatex, "\end{document}").start,false)
' oCurseurLatex.gotoRange(oCurseurDebut,false)
' oCurseurLatex.gotoRange(oCurseurFin,true)
i=instr(sTexteLatex,"\begin{document}")
if i>0 then i=i+len("\begin{document}")
j=instr(i,sTexteLatex,"\end{document}")
if i*j>0 then
'conversion
sTexteLatex=mid(sTexteLatex,i,j-i)
sTexteLatex=SubstitutionsLatexAvantTraitement(sTexteLatex)
DocLatex2OOo(oDocOOo, sTexteLatex)
else
msgbox("Je ne trouve pas le corps du document.")
end if
end if
end With
end sub
function bLitUneLigne(oCurseur as object, oCurseurFin as object, sLigne as string) as boolean
' lit la ligne commençant au curseur
' si trouvée, le curseur est placé en début de ligne suivante
' renvoie true si une ligne est lue
if oCurseur.text.compareRegionEnds(oCurseur,oCurseurFin)>0 Then
' if oCurseur.isStartOfSentence() and oCurseur.text.compareRegionEnds(oCurseur,oCurseurFin)>0 Then
'parcours de l'expression
oCurseur.gotoEndOfSentence( True )
sLigne=oCurseur.string
oCurseur.collapseToEnd()
bLitUneLigne=true
Do
If Not oCurseur.goRight(1, False ) Then Exit Do
' If Not oCurseur.gotoNextSentence( False ) Then Exit Do
Loop Until oCurseur.isStartOfSentence() or oCurseur.text.compareRegionEnds(oCurseur,oCurseurFin)<=0
else
bLitUneLigne=false
end if
end function
sub DocLatex2OOo(oDocOOo as object, sTexteLatex as string)
' convertit la zone de texte contenue dans sTexteLatex au format OOo et le recopie
' dans oDocOOo
dim oViewCurseurOOo as Object, oCurseurOOo as Object
dim oCurseur as object
dim sPolice as String, sFormule as String
dim iTaille as Integer, i as long, j as long, iFin as long
dim k as long, l as long
dim sCaractere as string, sLigne as string, sFormuleLatex as string, sFormuleOOo as string
dim sTexteEntreAccolades as string, sCommandeLatex as string
dim sGraisse as Single
dim iItalique as integer
dim iCasse as integer
dim iAlign as integer
dim lCouleurCarac as long
dim a as object
oViewCurseurOOo = oDocOOo.getCurrentController().getViewCursor()
oCurseurOOo=oViewCurseurOOo.Text.createTextCursorByRange(oViewCurseurOOo)
sPolice=oViewCurseurOOo.CharFontName
iTaille=oViewCurseurOOo.Charheight
iFin=len(sTexteLatex)
i=1
Do While i<=iFin
'parcours du contenu
sCaractere=mid(sTexteLatex,i,1)
' a=asc(sCaractere)
select case sCaractere
case "%"
'commentaire, rechercher chr(10)
j=i+instr(mid(sTexteLatex,i+1),chr(10))
if j=i then
'pas trouvé
i=iFin+1
else
i=j+1
end if
case chr(13)
' si 2 sauts de lignes alors saut de ligne sinon, ignorer
if mid(sTexteLatex,i+1,3)=chr(10)&chr(13)&chr(10) then
oDocOOo.Text.insertControlCharacter(oCurseurOOo,com.sun.star.text.ControlCharacter.LINE_BREAK,false)
i=i+4
else
if not(oCurseurOOo.isStartOfSentence()) then
oDocOOo.Text.insertString(oCurseurOOo," ",false)
end if
i=i+1
end if
case chr(10), chr(9)
i=i+1
case chr(32)
oDocOOo.Text.insertString(oCurseurOOo," ",false)
do
i=i+1
loop while mid(sTexteLatex,i,1)=chr(32)
'******************** \\\\\\\\\\\\\\\\ *********************************************
case "\"
i=i+1
if instr("{}",mid(sTexteLatex,i,1))>0 then
sCommandeLatex=mid(sTexteLatex,i,1)
j=i
else
mFormuleLatex2OOo.bTrouveExpressionDroite(sTexteLatex,i,j,sCommandeLatex)
end if
i=j+1
select case sCommandeLatex
case "{", "}"
oDocOOo.Text.insertString(oCurseurOOo,sCommandeLatex,false)
case "\"
oDocOOo.Text.insertControlCharacter(oCurseurOOo,com.sun.star.text.ControlCharacter.LINE_BREAK,false)
do while instr(chr(10)&chr(13),mid(sTexteLatex,j+1,1))>0 and j<iFin
j=j+1
loop
case "bf"
oCurseurOOo.CharWeight=com.sun.star.awt.FontWeight.BOLD
case "textrm", "texttt", "textmd", "textup", "textsf", "textnormal","section"
' ne rien faire pour le moment.
' à perfectionner plus tard
if mFormuleLatex2OOo.bTrouveExpressionDroite(sTexteLatex,i,j,sTexteEntreAccolades) then
DocLatex2OOo(oDocOOo, mid(sTexteEntreAccolades,2,len(sTexteEntreAccolades)-2))
else
DocLatex2OOo(oDocOOo, sTexteEntreAccolades)
end if
case "textbf"
sGraisse=oCurseurOOo.CharWeight
oCurseurOOo.CharWeight=com.sun.star.awt.FontWeight.BOLD
if mFormuleLatex2OOo.bTrouveExpressionDroite(sTexteLatex,i,j,sTexteEntreAccolades) then
DocLatex2OOo(oDocOOo, mid(sTexteEntreAccolades,2,len(sTexteEntreAccolades)-2))
else
DocLatex2OOo(oDocOOo, sTexteEntreAccolades)
end if
'restaurer l'état
oCurseurOOo.CharWeight=sGraisse
case "textsl", "textit", "emph"
iItalique=oCurseurOOo.CharPosture
oCurseurOOo.CharPosture=com.sun.star.awt.FontSlant.ITALIC
if mFormuleLatex2OOo.bTrouveExpressionDroite(sTexteLatex,i,j,sTexteEntreAccolades) then
DocLatex2OOo(oDocOOo, mid(sTexteEntreAccolades,2,len(sTexteEntreAccolades)-2))
else
DocLatex2OOo(oDocOOo, sTexteEntreAccolades)
end if
'restaurer l'état
oCurseurOOo.CharPosture=iItalique
case "textsc"
iCasse=oCurseurOOo.CharCaseMap
oCurseurOOo.CharCaseMap=com.sun.star.style.CaseMap.SMALLCAPS
if mFormuleLatex2OOo.bTrouveExpressionDroite(sTexteLatex,i,j,sTexteEntreAccolades) then
DocLatex2OOo(oDocOOo, mid(sTexteEntreAccolades,2,len(sTexteEntreAccolades)-2))
else
DocLatex2OOo(oDocOOo, sTexteEntreAccolades)
end if
'restaurer l'état
oCurseurOOo.CharCaseMap=iCasse
case "begin"
' ************************** begin *******************************************
' lire commande
mFormuleLatex2OOo.bTrouveExpressionDroite(sTexteLatex,i,j,sTexteEntreAccolades)
i=j+1
' aller chercher le bon \end
k=i
l=instr(mid(sTexteLatex,j+1),"\end"&sTexteEntreAccolades)-1
if l=-1 then
'pas de end trouvé
lCouleurCarac=oCurseurOOo.CharColor
oCurseurOOo.CharColor=RGB(200,0,0)
oDocOOo.Text.insertString(oCurseurOOo," \end" & sTexteEntreAccolades &" non trouvé ",false)
oCurseurOOo.CharColor=lCouleurCarac
DocLatex2OOo(oDocOOo, mid(sTexteLatex,i,iFin-i+1))
stop
else
j=j+l
end if
l=instr(mid(sTexteLatex,k,j-k),"\begin"&sTexteEntreAccolades)-1
do while l>=0
k=k+l+len("\begin"&sTexteEntreAccolades)
j=j+len("\end"&sTexteEntreAccolades)
l=instr(mid(sTexteLatex,j+1),"\end"&sTexteEntreAccolades)-1
if l=-1 then
'pas de end trouvé
lCouleurCarac=oCurseurOOo.CharColor
oCurseurOOo.CharColor=RGB(200,0,0)
oDocOOo.Text.insertString(oCurseurOOo," \end" & sTexteEntreAccolades &" non trouvé ",false)
oCurseurOOo.CharColor=lCouleurCarac
DocLatex2OOo(oDocOOo, mid(sTexteLatex,i,iFin-i+1))
stop
else
j=j+l
end if
l=instr(mid(sTexteLatex,k,j-k),"\begin"&sTexteEntreAccolades)-1
loop
' entre i et j : contenu
select case mid(sTexteEntreAccolades,2,len(sTexteEntreAccolades)-2)
case "math"
sFormuleOOo=mFormuleLatex2OOo.sFormuleLaTeX2OOo(mid(sTexteLatex,i,j-i))
InsereFormule(oDocOOo, oViewCurseurOOo, oCurseurOOo, sPolice, iTaille, sFormuleOOo, false)
case "displaymath","equation","equation*"
' si on est dans une liste : ne pas aller à la ligne
if isEmpty(oCurseurOOo.NumberingRules) then
iAlign=oCurseurOOo.ParaAdjust
oDocOOo.Text.insertControlCharacter(oCurseurOOo,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,false)
oCurseurOOo.ParaAdjust=com.sun.star.style.ParagraphAdjust.CENTER
end if
sFormuleOOo=mFormuleLatex2OOo.sFormuleLaTeX2OOo(mid(sTexteLatex,i,j-i))
InsereFormule(oDocOOo, oViewCurseurOOo, oCurseurOOo, sPolice, iTaille, sFormuleOOo, false)
if isEmpty(oCurseurOOo.NumberingRules) then
oDocOOo.Text.insertControlCharacter(oCurseurOOo,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,false)
oCurseurOOo.ParaAdjust=iAlign
end if
case "enumerate"
oDocOOo.Text.insertControlCharacter(oCurseurOOo,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,false)
if isEmpty(oCurseurOOo.NumberingRules) then
' mettre ici le style de numérotation
CreerStyleListeLatex(oDocOOo)
oCurseurOOo.NumberingStyleName="Liste Latex"
oCurseurOOo.ParaIsNumberingRestart=true
else
oCurseurOOo.NumberingLevel=oCurseurOOo.NumberingLevel+1
end if
DocLatex2OOo(oDocOOo, mid(sTexteLatex,i,j-i+1))
oDocOOo.Text.insertControlCharacter(oCurseurOOo,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,false)
'restaurer l'état
if oCurseurOOo.NumberingLevel=0 then
oCurseurOOo.NumberingStyleName=""
' oCurseurOOo.NumberingRules=0
' oDocOOo.Text.insertControlCharacter(oCurseurOOo,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,false)
' dim args1(0) as new com.sun.star.beans.PropertyValue, dispatcher as object
' args1(0).Name = "On"
' args1(0).Value = false
' dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
' dispatcher.executeDispatch(ThisComponent.CurrentController.Frame, ".uno:DefaultNumbering", "", 0, args1())
else
oCurseurOOo.NumberingLevel=oCurseurOOo.NumberingLevel-1
end if
case "itemize", "description", "list", "trivlist"
oDocOOo.Text.insertControlCharacter(oCurseurOOo,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,false)
if isEmpty(oCurseurOOo.NumberingRules) then
' mettre ici le style de numérotation
oCurseurOOo.NumberingStyleName="List 1"
else
oCurseurOOo.NumberingLevel=oCurseurOOo.NumberingLevel+1
end if
DocLatex2OOo(oDocOOo, mid(sTexteLatex,i,j-i+1))
'restaurer l'état
oDocOOo.Text.insertControlCharacter(oCurseurOOo,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,false)
if oCurseurOOo.NumberingLevel=0 then
oCurseurOOo.NumberingStyleName=""
else
oCurseurOOo.NumberingLevel=oCurseurOOo.NumberingLevel-1
end if
case "center"
iAlign=oCurseurOOo.ParaAdjust
oDocOOo.Text.insertControlCharacter(oCurseurOOo,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,false)
oCurseurOOo.ParaAdjust=com.sun.star.style.ParagraphAdjust.CENTER
DocLatex2OOo(oDocOOo, mid(sTexteLatex,i,j-i+1))
'restaurer l'état
oDocOOo.Text.insertControlCharacter(oCurseurOOo,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,false)
oCurseurOOo.ParaAdjust=iAlign
case "flushleft"
iAlign=oCurseurOOo.ParaAdjust
oDocOOo.Text.insertControlCharacter(oCurseurOOo,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,false)
oCurseurOOo.ParaAdjust=com.sun.star.style.ParagraphAdjust.LEFT
DocLatex2OOo(oDocOOo, mid(sTexteLatex,i,j-i+1))
'restaurer l'état
oDocOOo.Text.insertControlCharacter(oCurseurOOo,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,false)
oCurseurOOo.ParaAdjust=iAlign
case "flushright"
iAlign=oCurseurOOo.ParaAdjust
oDocOOo.Text.insertControlCharacter(oCurseurOOo,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,false)
oCurseurOOo.ParaAdjust=com.sun.star.style.ParagraphAdjust.RIGHT
DocLatex2OOo(oDocOOo, mid(sTexteLatex,i,j-i+1))
'restaurer l'état
oDocOOo.Text.insertControlCharacter(oCurseurOOo,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,false)
oCurseurOOo.ParaAdjust=iAlign
case "picture","pspicture"
'environnements non traduits
lCouleurCarac=oCurseurOOo.CharColor
oCurseurOOo.CharColor=RGB(200,0,0)
oDocOOo.Text.insertControlCharacter(oCurseurOOo,com.sun.star.text.ControlCharacter.LINE_BREAK,false)
oDocOOo.Text.insertString(oCurseurOOo,"Environnement " & sTexteEntreAccolades &" non traduit.",false)
oCurseurOOo.CharColor=lCouleurCarac
oDocOOo.Text.insertControlCharacter(oCurseurOOo,com.sun.star.text.ControlCharacter.LINE_BREAK,false)
'oDocOOo.Text.insertControlCharacter(oCurseurOOo,com.sun.star.text.ControlCharacter.LINE_BREAK,false)
'oDocOOo.Text.insertString(oCurseurOOo,mid(sTexteLatex,i,j-i+1),false)
'oDocOOo.Text.insertControlCharacter(oCurseurOOo,com.sun.star.text.ControlCharacter.LINE_BREAK,false)
'oCurseurOOo.CharColor=RGB(200,0,0)
'oDocOOo.Text.insertString(oCurseurOOo,"Fin de l'environnement " & sTexteEntreAccolades ,false)
'oDocOOo.Text.insertControlCharacter(oCurseurOOo,com.sun.star.text.ControlCharacter.LINE_BREAK,false)
'oCurseurOOo.CharColor=lCouleurCarac
case else
' non implémenté encore : traduire l'intérieur
lCouleurCarac=oCurseurOOo.CharColor
oCurseurOOo.CharColor=RGB(200,0,0)
oDocOOo.Text.insertControlCharacter(oCurseurOOo,com.sun.star.text.ControlCharacter.LINE_BREAK,false)
oDocOOo.Text.insertString(oCurseurOOo,"Environnement " & sTexteEntreAccolades &" non implémenté, tentative de traduction :",false)
oCurseurOOo.CharColor=lCouleurCarac
oDocOOo.Text.insertControlCharacter(oCurseurOOo,com.sun.star.text.ControlCharacter.LINE_BREAK,false)
'oDocOOo.Text.insertControlCharacter(oCurseurOOo,com.sun.star.text.ControlCharacter.LINE_BREAK,false)
DocLatex2OOo(oDocOOo, mid(sTexteLatex,i,j-i+1))
oCurseurOOo.CharColor=RGB(200,0,0)
oDocOOo.Text.insertControlCharacter(oCurseurOOo,com.sun.star.text.ControlCharacter.LINE_BREAK,false)
oDocOOo.Text.insertString(oCurseurOOo,"Fin de l'environnement " & sTexteEntreAccolades ,false)
oDocOOo.Text.insertControlCharacter(oCurseurOOo,com.sun.star.text.ControlCharacter.LINE_BREAK,false)
oCurseurOOo.CharColor=lCouleurCarac
end select
'j=après le } du \end
j=j+len("\end"&sTexteEntreAccolades)
' ************************** begin *******************************************
case "item"
if oCurseurOOo.isStartOfSentence=false then
oDocOOo.Text.insertControlCharacter(oCurseurOOo,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,false)
end if
j=j+1
case else
' si argument suivant entre {} alors afficher le texte contenu dans les {}
' suppose qu'il n'y a qu'un argument
' à perfectionner, certaines commandes ont x>1 arguments
k=i
if mFormuleLatex2OOo.bTrouveExpressionDroite(sTexteLatex,k,l,sTexteEntreAccolades) then
oCurseurOOo.CharColor=RGB(200,0,0)
oDocOOo.Text.insertString(oCurseurOOo,"commande " & sCommandeLatex & " non implémentée " ,false)
oCurseurOOo.CharColor=lCouleurCarac
oDocOOo.Text.insertString(oCurseurOOo,sTexteEntreAccolades ,false)
j=l
end if
end select
i=j+1
'***************** \\\\\\\\\\\\\\\\\\\\\\\\\ ******************************************
case "$"
if mid(sTexteLatex,i,2)="$$" then
'mode centré
' oDocOOo.Text.insertControlCharacter(oCurseurOOo,com.sun.star.text.ControlCharacter.LINE_BREAK,false)
iAlign=oCurseurOOo.ParaAdjust
' si on est dans une liste : ne pas aller à la ligne
if isEmpty(oCurseurOOo.NumberingRules) then
oDocOOo.Text.insertControlCharacter(oCurseurOOo,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,false)
oCurseurOOo.ParaAdjust=com.sun.star.style.ParagraphAdjust.CENTER
end if
bModeTexte=false
i=i+2
else
'mode texte
bModeTexte=true
i=i+1
end if
j=i
sFormuleLatex=""
do
sCaractere=mid(sTexteLatex,j,1)
' ignorer les commentaires
if sCaractere="%" then
do
j=j+1
sCaractere=mid(sTexteLatex,j,1)
loop while sCaractere<>chr(10) and j<iFin
end if
if sCaractere>=" " then sFormuleLatex=sFormuleLatex+sCaractere
j=j+1
loop while sCaractere<>"$" and j<=iFin
if sCaractere="$" then
sFormuleOOo=mFormuleLatex2OOo.sFormuleLaTeX2OOo(left(sFormuleLatex,len(sFormuleLatex)-1))
else
sFormuleOOo="""Formule incomplète"""
end if
' mettre bModeTexte à la place de false quand OOo ne sera plus bogué
InsereFormule(oDocOOo, oViewCurseurOOo, oCurseurOOo, sPolice, iTaille, sFormuleOOo, false)
if bModeTexte or sCaractere<>"$" then
i=j
else
i=j+1
'restaurer l'état
if isEmpty(oCurseurOOo.NumberingRules) then
oDocOOo.Text.insertControlCharacter(oCurseurOOo,com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK,false)
oCurseurOOo.ParaAdjust=iAlign
end if
' oDocOOo.Text.insertControlCharacter(oCurseurOOo,com.sun.star.text.ControlCharacter.LINE_BREAK,false)
end if
case "{"
'sauvegarder l'état : gras, italic
sGraisse=oCurseurOOo.CharWeight
iItalique=oCurseurOOo.CharPosture
mFormuleLatex2OOo.bTrouveExpressionDroite(sTexteLatex,i,j,sTexteEntreAccolades)
DocLatex2OOo(oDocOOo, mid(sTexteEntreAccolades,2,len(sTexteEntreAccolades)-2))
'restaurer l'état
oCurseurOOo.CharWeight=sGraisse
oCurseurOOo.CharPosture=iItalique
i=j+1
case else
oDocOOo.Text.insertString(oCurseurOOo,sCaractere,false)
i=i+1
end select
Loop
end sub
Sub InsereFormule(oDoc as object, oViewCursor as Object, oTextCursor as Object, sPolice as String, iTaille as Integer, sFormule as String, bModeTexte as boolean)
dim obj as object, document as object
obj=ThisComponent.CreateInstance("com.sun.star.text.TextEmbeddedObject")
obj.CLSID="078B7ABA-54FC-457F-8551-6147e776a997"
obj.AnchorType=com.sun.star.text.TextContentAnchorType.AS_CHARACTER
document = oDoc.CurrentController.Frame
oDoc.getCurrentController().select(oTextCursor)
oTextCursor.Text.insertTextContent(oTextCursor, obj, true)
obj.EmbeddedObject.BaseFontHeight=iTaille
obj.EmbeddedObject.FontNameVariables=sPolice
obj.EmbeddedObject.FontVariablesIsItalic=true
obj.EmbeddedObject.FontNameNumbers=sPolice
if IsMacOs then 'Mac
obj.EmbeddedObject.CustomFontNameSans="Cmath Calligraphique"
obj.EmbeddedObject.CustomFontNameSerif="Cmath Script"
else
obj.EmbeddedObject.CustomFontNameSans="Cmathcal"
obj.EmbeddedObject.CustomFontNameSerif="Cmathscr"
end if
obj.EmbeddedObject.FontNameText=sPolice
obj.EmbeddedObject.FontNameFunctions=sPolice
obj.EmbeddedObject.IsScaleAllBrackets=True
obj.EmbeddedObject.RelativeIndexSubscript=0
obj.EmbeddedObject.RelativeIndexSuperscript=0
obj.EmbeddedObject.formula=sFormule
' obj.EmbeddedObject.LeftMargin=20
' obj.EmbeddedObject.RightMargin=20
obj.EmbeddedObject.IsTextMode=bModeTexte
obj.EmbeddedObject.setmodified(TRUE)
obj.LeftMargin=0
obj.RightMargin=0
oViewCursor.goLeft(1,False)
oViewCursor.goRight(1,False)
' dim dispatcher as object, obj as object, document as object
' ThisComponent.lockControllers
' oTextCursor.Text.insertString(oTextCursor, sFormule, true)
' oViewCursor.gotoRange(oTextCursor,true)
' document = oDoc.CurrentController.Frame
' dim Array(0) as new com.sun.star.beans.PropertyValue
' dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
' dispatcher.executeDispatch(document, ".uno:InsertObjectStarMath", "", 0,Array())
' ThisComponent.unlockControllers
' obj=oDoc.getCurrentSelection()
' obj.EmbeddedObject.FontNameVariables=sPolice
' obj.EmbeddedObject.FontVariablesIsItalic=true
' obj.EmbeddedObject.FontNameNumbers=sPolice
' obj.EmbeddedObject.FontNameText=sPolice
' obj.EmbeddedObject.FontNameFunctions=sPolice
' obj.EmbeddedObject.BaseFontHeight=iTaille
' obj.EmbeddedObject.IsScaleAllBrackets=True
' obj.EmbeddedObject.RelativeIndexSubscript=0
' obj.EmbeddedObject.RelativeIndexSuperscript=0
' obj.EmbeddedObject.IsTextMode=bModeTexte
' obj.EmbeddedObject.setmodified(TRUE)
' obj.LeftMargin=0
' obj.RightMargin=0
' dispatcher.executeDispatch(document, ".uno:Escape", "", 0, Array())
' dispatcher.executeDispatch(document, ".uno:ResetAttributes", "", 0, Array())
' wait 120
'
' oViewCursor.gotoRange(oTextCursor,false)
' oViewCursor.goLeft(1,False)
' oViewCursor.goRight(1,False)
end sub
function oTrouveExpression(oDocLatex as object, oCurseurLatex as object, sChaine as string) as object
' trouve une chaine dans le document oDocLatex à partir de oCurseurLatex.
' renvoie le curseur pointant sur le 1er caractère de la chaine
' et sur la fin si pas trouvé
dim oCurseur as object
dim sLigne as string, i as long
oCurseur=oDocLatex.Text.createTextCursorByRange(oCurseurLatex.Start)
Do While bLitUneLigne(oCurseur,oCurseurLatex.End,sLigne)
i=instr(sLigne,sChaine)
if i>0 then
'Do
' If Not oCurseur.gotoPreviousSentence( false ) Then Exit Do
'Loop Until oCurseur.isStartOfSentence()
oCurseur.goleft(len(sChaine)+1,false)
'oCurseur.goRight(i-1,false)
oTrouveExpression=oCurseur
exit do
else
oTrouveExpression=oCurseurLatex.End
end if
loop
end function
Sub SetNumberingRuleProperty( oCursor,_
ByVal nNumberingLevel As Long,_
ByVal cPropertyName As String,_
ByVal value )
dim oNumberingRules as object, oNumLevelProperties as object, nPropIndex as integer, oProp as object
' From the cursor, get the NumberingRules.
' Here's how this works.
' The oCursor contains a TextCursor -- described here...
' http://api.openoffice.org/docs/common/ref/com/sun/star/text/TextCursor.html
' This service includes a TextRange -- described here...
' http://api.openoffice.org/docs/common/ref/com/sun/star/text/TextRange.html
' This service includes the servics CharacterProperties and ParagraphProperties.
' Looking closer at ParagraphProperties...
' http://api.openoffice.org/docs/common/ref/com/sun/star/style/ParagraphProperties.html
' you can see that it has the property NumberingRules.
' Hence, that is how the next line of code works, it gets the Numbering rules property.
'
' The object assigned is a...
' http://api.openoffice.org/docs/common/ref/com/sun/star/text/NumberingRules.html
oNumberingRules = oCursor.NumberingRules
' Get the numbering level.
' It is an array of PropertyValue's.
oNumLevelProperties = oNumberingRules.getByIndex( nNumberingLevel )
' Now find which property number we are interested in.
nPropIndex = FindPropertyIndex( oNumLevelProperties, cPropertyName )
' If we found the property...
If nPropIndex >= 0 Then
' Get the property by accessing array subscript.
oProp = oNumLevelProperties(nPropIndex)
oProp.Value = value
' Put the property back into the array.
oNumLevelProperties(nPropIndex) = oProp
' Now put the array back into the NumberingLevel.
oNumberingRules.replaceByIndex( nNumberingLevel, oNumLevelProperties )
oCursor.NumberingRules = oNumberingRules
EndIf
End Sub
'
Function FindProperty( aArrayOfProperties, cPropName As String ) As com.sun.star.beans.PropertyValue
dim oProp as object
dim nPropIndex as integer
nPropIndex = FindPropertyIndex( aArrayOfProperties, cPropName )
If nPropIndex >= 0 Then
oProp = aArrayOfProperties(nPropIndex) ' access array subscript
FindProperty() = oProp
EndIf
End Function
Function FindPropertyIndex( aArrayOfProperties, cPropName As String ) As Long
dim i as integer
dim oProp as object
For i = LBound( aArrayOfProperties ) To UBound( aArrayOfProperties )
oProp = aArrayOfProperties(i)
If oProp.Name = cPropName Then
FindPropertyIndex() = i
Exit Function
EndIf
Next
End Function
sub CreerStyleListeLatex(oDoc as object)
dim lesFamilles as object, uneFamille as object, nouvStyle as object
lesFamilles=oDoc.StyleFamilies
uneFamille=lesFamilles.getByName("NumberingStyles")
if uneFamille.hasByName("Liste Latex") then
nouvStyle=uneFamille.getByName("Liste Latex")
else
'création
nouvStyle=oDoc.CreateInstance("com.sun.star.style.NumberingStyle")
uneFamille.insertByName("Liste Latex",nouvStyle)
' nouvStyle.NumberingRules.IsAutomatic=true
' nouvStyle.NumberingRules.IsContinuousNumbering=true
SetNumberingRuleProperty(nouvStyle,0,"LeftMargin",600)
SetNumberingRuleProperty(nouvStyle,0,"FirstLineOffset",-600)
SetNumberingRuleProperty(nouvStyle,0,"SymbolTextDistance",0)
SetNumberingRuleProperty(nouvStyle,0,"NumberingType",com.sun.star.style.NumberingType.ARABIC)
SetNumberingRuleProperty(nouvStyle,1,"LeftMargin",1200)
SetNumberingRuleProperty(nouvStyle,1,"FirstLineOffset",-600)
SetNumberingRuleProperty(nouvStyle,1,"SymbolTextDistance",0)
SetNumberingRuleProperty(nouvStyle,1,"NumberingType",com.sun.star.style.NumberingType.CHARS_LOWER_LETTER)
SetNumberingRuleProperty(nouvStyle,2,"LeftMargin",1800)
SetNumberingRuleProperty(nouvStyle,2,"FirstLineOffset",-600)
SetNumberingRuleProperty(nouvStyle,2,"SymbolTextDistance",0)
SetNumberingRuleProperty(nouvStyle,2,"NumberingType",com.sun.star.style.NumberingType.ROMAN_LOWER)
end if
' a=nouvStyle.NumberingRules
' b=a.getCount()
' c=a.getByIndex(0)
' d=c(10)
'SetNumberingRuleProperty(nouvStyle,0,"CharStyleName","Bullet Symbols")
'SetNumberingRuleProperty(nouvStyle,0,"BulletChar", chr(2022))
end sub
function SubstitutionsLatexAvantTraitement(sTexteLatex as String) as String
dim sSearch() as string, sReplace() as string
dim n as integer, i as long
sSearch() = Array("\(","\)","\[","\]",_
"~","\'e","\`e","\^e","\`u","\^{\i}","\^o","\`a","\¨e","\^a",_
"\\","\begin {","\end {",chr(13)&chr(13),chr(10)&chr(10),_
"\"&chr(13),"\"&chr(10))
sReplace() = Array("$","$","$$","$$",_
" ","é","è","ê","ù","î","ô","à","ë","â",_
"\\ ","\begin{","\end{",chr(13)&chr(10)&chr(13)&chr(10),chr(13)&chr(10)&chr(13)&chr(10),_
"","")
For n = LBound(sSearch()) To UBound(sSearch())
i=Instr(sTexteLatex,sSearch(n))
do while i>0
sTexteLatex=left(sTexteLatex,i-1)+sReplace(n)+mid(sTexteLatex,i+len(sSearch(n)))
i=Instr(i+len(sReplace(n)),sTexteLatex,sSearch(n))
loop
Next n
SubstitutionsLatexAvantTraitement=sTexteLatex
end function
function TraduitNewCommand(sTexteLatex as String) as String
' recherche \newcommand, \renewcommand, \def et substitue dans le texte
dim sSearch() as string, sReplace() as string
dim n as integer, i as long, j as long, k as long, k0 as long, l as long,m as long
dim sNom as string, sDefinition as string, sTexteSubstitue as string, sNomLu as string
dim iNbArg as integer
dim sArg(1 to 9) as string
sSearch() = Array("\newcommand","\renewcommand","\providecommand","\def")
For n = LBound(sSearch()) To UBound(sSearch())
i=Instr(sTexteLatex,sSearch(n))
do while i>0
i=i+len(sSearch(n))
if mFormuleLatex2OOo.bTrouveExpressionDroite(sTexteLatex,i,j,sNom)=true then
sNom=mid(sNom,2,len(sNom)-2)
end if
i=j+1
if mFormuleLatex2OOo.bTrouveExpressionDroite(sTexteLatex,i,j,sDefinition)=true then
'il n'y a pas d'argument à la commande
' substitution
k=j+1
k=Instr(k,sTexteLatex,sNom,0)
do while k>0
mFormuleLatex2OOo.bTrouveExpressionDroite(sTexteLatex,k,l,sNomLu)
if sNomlu=sNom then
sTexteLatex=left(sTexteLatex,k-1)+mid(sDefinition,2,len(sDefinition)-2)+mid(sTexteLatex,k+len(sNom))
k=k+len(sDefinition)-2
k=Instr(k,sTexteLatex,sNom,0)
else
k=k+len(sNomLu)
k=Instr(k,sTexteLatex,sNom,0)
end if
loop
elseif left(sDefinition,1)="[" then
'il y a au moins un argument
'lire le nombre d'argument
iNbArg=val(mid(sDefinition,2,1))
i=j+2
'lire la définition
if mFormuleLatex2OOo.bTrouveExpressionDroite(sTexteLatex,i,j,sDefinition)=false then
' lire la valeur par défaut de #1
j=instr(i+1,sTexteLatex,"]")
sDefaut=mid(sTexteLatex,i+1,j-1)
i=j+1
mFormuleLatex2OOo.bTrouveExpressionDroite(sTexteLatex,i,j,sDefinition)
end if
sDefinition=mid(sDefinition,2,len(sDefinition)-2)
' substitution
k0=j+1
k0=Instr(k0,sTexteLatex,sNom,0)
do while k0>0
mFormuleLatex2OOo.bTrouveExpressionDroite(sTexteLatex,k0,l,sNomLu)
if sNomlu=sNom then
' lecture des arguments
sTexteSubstitue=sDefinition
k=k0+len(sNom)
mFormuleLatex2OOo.bTrouveExpressionDroite(sTexteLatex,k,l,sArg(1))
if sArg(1)="{}" then sArg1=sDefaut
for m=2 to iNbArg
k=l+1
mFormuleLatex2OOo.bTrouveExpressionDroite(sTexteLatex,k,l,sArg(m))
next m
' enlever les {} et substituer les #m
for m=1 to iNbArg
sArg(m)=mid(sArg(m),2,len(sArg(m))-2)
Substitue(sTexteSubstitue,1,len(sTexteSubstitue),"#"+LTrim(str(m)),"{"&sArg(m)&"}")
next m
sTexteLatex=left(sTexteLatex,k0-1)+sTexteSubstitue+mid(sTexteLatex,l+1)
k0=k0+len(sTexteSubstitue)
k0=Instr(k0,sTexteLatex,sNom,0)
else
k0=k0+len(sNomLu)
k0=Instr(k0,sTexteLatex,sNom,0)
end if
loop
end if
i=j+1
i=Instr(i,sTexteLatex,sSearch(n))
loop
Next n
TraduitNewCommand=sTexteLatex
end function
sub Substitue(sChaine as String, i as long, j as long, sChercher as String, sRemplacer as String) as integer
' cherche et remplace dans sChaine de la position i à j la chaine sChercher par sRemplacer
Dim iNiveau as integer, k as long, iNB as long
dim jtemp as long
iNb=0
k=i
jtemp=j
iNiveau=0
do while k<=jtemp-len(sChercher)+1
if mid(sChaine,k,len(sChercher))=sChercher then
sChaine=left(sChaine,k-1) & sRemplacer & mid(sChaine,k+len(sChercher))
jtemp=jtemp+len(sRemplacer)-len(sChercher)
k=k+len(sRemplacer)-1
iNb=iNb+1
end if
k=k+1
loop
j=jtemp
end sub
Function DetermineOS as Integer
If Getguitype = 1 Then
DetermineOS = 1
ElseIf Getguitype = 4 and FileExists("/Users") Then
DetermineOS = 3
Else
DetermineOS = 4
Endif
End Function
Function IsMacOS as Boolean
IsMacOS = False
If Getguitype = 4 and FileExists("/Users") Then IsMacOS = True
End Function
</script:module>
|