csl-clio/Macros/LibreOffice/ApresZotero/ApZotFunctions.xba

576 lines
93 KiB
Plaintext
Raw Permalink Normal View History

<?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="ApZotFunctions" script:language="StarBasic">REM ***** BASIC *****
&apos;************************************************************************
&apos;* Copyright 2021 by Bastien Dumont (bastien.dumont@posteo.net)
&apos;*
&apos;* This file is part of the ApresZotero library.
&apos;*
&apos;* ApresZotero is free software: you can redistribute it and/or modify
&apos;* it under the terms of the GNU General Public License as published by
&apos;* the Free Software Foundation, either version 3 of the License, or
&apos;* (at your option) any later version.
&apos;*
&apos;* ApresZotero is distributed in the hope that it will be useful,
&apos;* but WITHOUT ANY WARRANTY; without even the implied warranty of
&apos;* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
&apos;* GNU General Public License for more details.
&apos;*
&apos;* You should have received a copy of the GNU General Public License
&apos;* along with ApresZotero. If not, see &lt;https://www.gnu.org/licenses/&gt;.
&apos;*
&apos;************************************************************************
Option Compatible
Option Explicit
Function Check (mJournal As String) As Integer
Dim iReturnCode As Long
iReturnCode = MsgBox(&quot;Avez-vous terminé de modifier le document et actualisé les citations Zotéro ?&quot;, 4, mJournal)
If iReturnCode = 7 Then
MsgBox(&quot;Veuillez terminer votre travail sur le document et actualiser les citations avant de lancer la macro.&quot;, 0, mJournal)
End If
Check = iReturnCode
End Function
Sub Abbreviate (oDocument As Object, mTitreLong() As Variant, mAbrev() As Variant, mEditeur As String, bExpandFirstCitation As Boolean)
REM Cette subroutine devrait devenir obsolète si les pistes envisagées dans le fil et la page ci-dessous se concrétisent :
REM https://forums.zotero.org/discussion/comment/325925#Comment_325925
REM https://www.zotero.org/support/kb/journal_abbreviations
Dim oSearch As Object
Dim sCited As String
Dim oCursor As Object
Dim n As Integer
Dim oOccurrence As Object
Dim bAlreadyAbbreviated As Boolean
Dim iReturnCode As Integer
Dim vCharPosture As Variant
On Error Goto ErrorHandler &apos;Si l&apos;utilisateur a tenté de lancer cette sous-routine, oDocument n&apos;est pas défini.
oSearch = oDocument.createSearchDescriptor()
oSearch.SearchWords = TRUE
oSearch.SearchRegularExpression = FALSE
oSearch.SearchCaseSensitive = FALSE
On Error GoTo 0
oCursor = oDocument.getCurrentController.getViewCursor()
For n = lbound(mTitreLong) To ubound(mTitreLong)
oSearch.SearchString = mTitreLong(n)
oOccurrence = oDocument.findFirst(oSearch)
bAlreadyAbbreviated = FALSE
Do While Not IsNull(oOccurrence)
oCursor.gotoRange(oOccurrence, False)
iReturnCode = MsgBox(&quot;Remplacer le texte sélectionné par l&apos;abréviation correspondante ?&quot;, 3, mEditeur)
If iReturnCode = 2 Then &apos;Cancel
MsgBox(&quot;Vous avez arrêté l&apos;exécution de la macro, mais les éventuels titres de revues déjà remplacés n&apos;ont pas été restaurés.&quot;, 0, mEditeur)
Exit Sub
ElseIf iReturnCode = 6 Then &apos;Yes
vCharPosture = oCursor.CharPosture
If bExpandFirstCitation AND bAlreadyAbbreviated = FALSE Then
oCursor.collapseToEnd()
oCursor.setString(&quot; (&quot; &amp; mAbrev(n) &amp; &quot;)&quot;)
oCursor.CharPosture = vCharPosture
bAlreadyAbbreviated = TRUE
Else
oCursor.setString(mAbrev(n))
oCursor.CharPosture = vCharPosture
End If
ElseIf iReturnCode = 7 Then &apos;No
End If
oOccurrence = oDocument.findNext(oOccurrence.End, oSearch)
Loop
Next n
Exit Sub
ErrorHandler:
If Err = 449 Then
MsgBox(&quot;La macro Abbreviate n&apos;est pas destinée à être lancée directement par l&apos;utilisateur. &quot;&amp;_
&quot;Veuillez lancer la macro correspondant au nom de la revue souhaité.&quot;, 0, &quot;Erreur&quot;)
Else
MsgBox(Error$, 0, &quot;Erreur&quot;)
End If
On Error Goto 0
End Sub
Sub SetStringPartToExponent(oScope As Object, sWholeStringRegex As String, sSubstringInExponentRegex As String)
Dim oViewProperties As Object
Dim nCurrentZoomFactor As Integer
Dim oWholeStringSearch As Object
Dim oWholeStringResult As Object
Dim oFound As Object
Dim iResult As Integer
Dim oFoundCursor As Object
Dim iReturnCode As Integer
oViewProperties = ThisComponent.getViewData().getByIndex(0)
nCurrentZoomFactor = getCurrentZoomFactor()
ThisComponent.CurrentController.ViewSettings.ZoomType = 3
ThisComponent.CurrentController.ViewSettings.ZoomValue = nBigZoomFactor
oWholeStringSearch = ThisComponent.createSearchDescriptor
oWholeStringSearch.SearchString = sWholeStringRegex
oWholeStringSearch.SearchRegularExpression = TRUE
oWholeStringResult = oScope.findAll(oWholeStringSearch)
oFoundCursor = ThisComponent.getCurrentController.getViewCursor()
For iResult = 0 To oWholeStringResult.count - 1
oFound = oWholeStringResult.getByIndex(iResult)
oFoundCursor.gotoRange(oFound, False)
PlaceCursorOnSubstring(oFoundCursor, sSubstringInExponentRegex)
iReturnCode = MsgBox(&quot;Mettre le texte surligné en exposant ?&quot;, 3)
If iReturnCode = 2 Then &apos;Cancel
MsgBox(&quot;Vous avez arrêté l&apos;exécution de la macro, mais les actions déjà réalisées n&apos;ont pas été annulées.&quot;, 0)
ThisComponent.CurrentController.ViewSettings.ZoomValue = nCurrentZoomFactor
Exit Sub
ElseIf iReturnCode = 6 Then &apos;Yes
oFoundCursor.CharEscapement = nExponentCharSizePercentage
oFoundCursor.CharEscapementHeight = nExponentCharHeightPercentage
ElseIf iReturnCode = 7 Then &apos;No
End If
Next iResult
ThisComponent.CurrentController.ViewSettings.ZoomValue = nCurrentZoomFactor
End Sub
Function getCurrentZoomFactor() As Integer
Dim oDocument As Object
Dim oViewProperties As Object
Dim iProperty As Integer
oViewProperties = ThisComponent.getViewData().getByIndex(0)
For iProperty = 0 to UBound(oViewProperties)
If oViewProperties(iProperty).Name = &quot;ZoomFactor&quot; Then
getCurrentZoomFactor = oViewProperties(iProperty).Value
End If
Next iProperty
End Function
Sub PlaceCursorOnSubstring(oCursor As Object, sSubstringRegex As String)
Dim oSubstringSearch As Object
Dim oResult As Object
oSubstringSearch = ThisComponent.createSearchDescriptor()
oSubstringSearch.SearchString = sSubstringRegex
oSubstringSearch.SearchRegularExpression = TRUE
oResult = ThisComponent.findNext(oCursor.getStart(), oSubstringSearch)
oCursor.gotoRange(oResult, FALSE)
End Sub
Function extractMatchingString(sSearchedString As String, aSearchResult As Object, iMatch As Integer, nCharsToIgnore As Integer) As String
Dim iMatchStartPos As Integer
Dim nMatchLen As Integer
iMatchStartPos = aSearchResult.startOffset(iMatch) + 1
nMatchLen = aSearchResult.endOffset(iMatch) - aSearchResult.startOffset(iMatch)
extractMatchingString = Mid(sSearchedString, iMatchStartPos+nCharsToIgnore, nMatchLen-nCharsToIgnore)
End Function
Sub AddItemToMap(vMap() As Variant, sID As String, sTitle As String)
Dim iItem As Integer
For iItem = LBound(vMap(), 1) To UBound(vMap(), 1)
If vMap(iItem, 0) = sID Then
vMap(iItem, 2) = vMap(iItem, 2)+1
Exit Sub
End If
Next iItem
vMap(UBound(vMap(), 1), 0) = sID
vMap(UBound(vMap(), 1), 1) = sTitle
vMap(UBound(vMap(), 1), 2) = 1
ReDim Preserve vMap(UBound(vMap(), 1)+1, 3) As Variant
End Sub
Function sortMapByNbOccurrences(ByVal vMap() As Variant)
Dim vSortedMap(UBound(vMap(), 1), 3) As Variant
Dim iSortedMap As Integer
Dim nMaxOccurrences As Integer
Dim iNbOccurrences As Integer
Dim iMap As Integer
nMaxOccurrences = getMaxOccurrences(vMap)
iSortedMap = 0
For iNbOccurrences = nMaxOccurrences To 1 Step -1
For iMap = LBound(vMap(), 1) To UBound(vMap(), 1)
If vMap(iMap, 2) = iNbOccurrences Then
vSortedMap(iSortedMap, 0) = vMap(iMap, 0)
vSortedMap(iSortedMap, 1) = vMap(iMap, 1)
vSortedMap(iSortedMap, 2) = iNbOccurrences
iSortedMap = iSortedMap+1
End If
Next iMap
Next iNbOccurrences
sortMapByNbOccurrences = vSortedMap
End Function
Function getMaxOccurrences(vMap As Variant)
Dim nCurrentOccurrences As Integer
Dim iMap As Integer
For iMap = LBound(vMap(), 1) To UBound(vMap(), 1)
If vMap(iMap, 2) &gt; nCurrentOccurrences Then
nCurrentOccurrences = vMap(iMap, 2)
End If
Next iMap
getMaxOccurrences = nCurrentOccurrences
End Function
Sub PrintMap(vMap() As Variant)
Dim oDocumentText As Object
Dim iMap As Integer
Dim sStringToInsert As String
oDocumentText = ThisComponent.Text
oDocumentText.insertString(oDocumentText.End, CHR$(10) &amp; CHR$(10) &amp; CHR$(10), False)
For iMap = LBound(vMap(), 1) To UBound(vMap(), 1)-1
sStringToInsert = vMap(iMap, 2) &amp; &quot; {&quot;&quot;&quot; &amp; vMap(iMap, 1) &amp; CHR$(10) &amp; CHR$(10)
oDocumentText.insertString(oDocumentText.End, sStringToInsert, False)
Next iMap
End Sub
Sub HandleItemsInBibliography&apos;(sBibliographyHeaderStyle As String)
Dim iReturnCode As Integer
Dim oBibliographyCursor As Object
Dim sAbbrevsAndExtendedList() As String
Const sBibliographyHeaderStyle As String = &quot;Titre Liste des abréviations&quot;
iReturnCode = MsgBox(&quot;Avez-vous créé une liste d&apos;abréviations ?&quot; &amp;_
&quot; Si oui, la première mention de chaque item dans la bibliographie sera abrégée.&quot;,_
4, &quot;Traitement des items de la bibliographie&quot;)
If iReturnCode = 7 Then
Exit Sub
End If
oBibliographyCursor= getBibliographyCursor(sBibliographyHeaderStyle)
sAbbrevsAndExtendedList() = createAbbrevsAndExtendedReferencesList(oBibliographyCursor)
SuppressFirstCitationReferenceForItemsInAbbrevList(sAbbrevsAndExtendedList)
MsgBox(&quot;Le traitement est terminé. Il vous reste à abréger manuellement la première référence de chaque item cité dans la bibliographie.&quot;)
End Sub
Function createAbbrevsAndExtendedReferencesList(oBibliographyCursor As Object)
Dim oFirstNoteText As Object
Dim sAbbrevsAndExtendedList() As String
Dim oTextCursorToStore As Object
Dim oNextParagraph As Object
Dim sAbbrev As String
Dim sExtendedReference As String
oBibliographyCursor.gotoNextParagraph(False)
oBibliographyCursor.gotoPreviousParagraph(False)
Do
oBibliographyCursor.collapseToStart()
Do While InStr(oBibliographyCursor.getString(), sSeparatorForListOfAbbreviations) = 0
oBibliographyCursor.goRight(1, True)
Loop
oBibliographyCursor.goLeft(1, True)
sAbbrev = oBibliographyCursor.getString()
AddToList(sAbbrev, sAbbrevsAndExtendedList)
ReplaceSeparator(oBibliographyCursor)
oBibliographyCursor.gotoEndOfParagraph(True)
sExtendedReference = oBibliographyCursor.getString()
AddToList(sExtendedReference, sAbbrevsAndExtendedList)
oBibliographyCursor.gotoNextParagraph(False)
oBibliographyCursor.gotoEndOfParagraph(True)
Loop While oBibliographyCursor.ParaStyleName = sBibliographyStyleName _
AND InStr(oBibliographyCursor.getString(), sSeparatorForListOfAbbreviations) &gt; 0
createAbbrevsAndExtendedReferencesList = sAbbrevsAndExtendedList
End Function
Sub ReplaceSeparator(oCursor As Object)
oCursor.collapseToEnd()
oCursor.goRight(1, True)
oCursor.setString(sReplacementSeparatorForListOfAbbreviations)
oCursor.CharPosture = &quot;com.sun.star.awt.FontSlant.NONE&quot;
oCursor.collapseToEnd()
End Sub
Sub AddToList(sString As String, sList() As String)
ReDim Preserve sList(UBound(sList)+1)
sList(UBound(sList)) = sString
End Sub
Sub SuppressFirstCitationReferenceForItemsInAbbrevList(sAbbrevsAndExtendedList As String)
Dim oDocument As Object
Dim oCitRefSearch As Object
Dim nReferences As Integer
Dim iAbbrev As Integer
Dim sAbbrevString As String
Dim oCitRefResult As Object
Dim oCitRefFoundCursor As Object
Dim oCitRefFound As Object
Dim iResult As Integer
oDocument = ThisComponent
oCitRefSearch = oDocument.createSearchDescriptor()
For iAbbrev = LBound(sAbbrevsAndExtendedList) To UBound(sAbbrevsAndExtendedList)-1 Step 2
sAbbrevString = sAbbrevsAndExtendedList(iAbbrev)
oCitRefSearch.SearchString = sAbbrevString &amp; sFirstCitationPrefix &amp; &quot;[0-9]+&quot;
oCitRefSearch.SearchRegularExpression = TRUE
oCitRefResult = oDocument.findAll(oCitRefSearch)
oCitRefFoundCursor = ThisComponent.getCurrentController.getViewCursor()
For iResult = 0 To oCitRefResult.count - 1
oCitRefFound = oCitRefResult.getByIndex(iResult)
oCitRefFoundCursor.gotoRange(oCitRefFound, False)
oCitRefFoundCursor.goRight(Len(sAbbrevString), True)
oCitRefFoundCursor.setString(&quot;&quot;)
Next iResult
Next iAbbrev
End Sub
Sub AbbreviateFirstOccurrences(oAbbrevAndReferencesList As Object)
Dim oDocument As Object
Dim oFootnotes As Object
Dim iExpandedReference As Integer
Dim oExpandedRefSearch As Object
Dim oFirstOccurrence As Object
Dim oCopyPasteCursor As Object
Dim oFrame As Object
Dim oDispatcher As Object
oDocument = ThisComponent
oCopyPasteCursor = oDocument.currentController.getViewCursor()
oFrame = oDocument.CurrentController.Frame
oDispatcher = createUnoService(&quot;com.sun.star.frame.DispatchHelper&quot;)
oExpandedRefSearch = oDocument.createSearchDescriptor()
For iExpandedReference = 1 To UBound(oAbbrevAndReferencesList) Step 2
oExpandedRefSearch.SearchString = oAbbrevAndReferencesList(iExpandedReference).getString()
oExpandedRefSearch.SearchRegularExpression = FALSE
oFirstOccurrence = oDocument.findFirst(oExpandedRefSearch)
oFirstOccurrence.setString(&quot;&quot;)
oCopyPasteCursor.gotoRange(oAbbrevAndReferencesList(iExpandedReference)-1, False)
oDispatcher.executeDispatch(oFrame, &quot;.uno:Copy&quot;, &quot;&quot;, 0, Array())
oCopyPasteCursor.gotoRange(oFirstOccurrence, False)
oCopyPasteCursor.CharCaseMap = 0
oCopyPasteCursor.CharPosture = &quot;com.sun.star.awt.FontSlant.NONE&quot;
oCopyPasteCursor.ParaStyleName = &quot;Style par défaut&quot;
oDispatcher.executeDispatch(oFrame, &quot;.uno:Paste&quot;, &quot;&quot;, 0, Array())
Next iExpandedReference
End Sub
Sub AbbrevAnnee_Philologique(bExpandFirstCitation as Boolean)
Const mJournal As String = &quot;Année Philologique&quot;
Dim mTitreLong() As String
mTitreLong = Array(&quot;Antike und Abendland&quot;, &quot;Antigüedad y cristianismo&quot;, &quot;Atene e Roma&quot;, &quot;Archäologischer Anzeiger / Deutsches Archäologisches Institut&quot;, &quot;Acta ad archaeologiam et artium historiam pertinentia. Series altera in 8o;&quot;, &quot;Annuaire / Amis de la Bibliothèque humaniste de Sélestat&quot;, &quot;Anales de arqueología cordobesa&quot;, &quot;Annuario / Accademia Etrusca di Cortona&quot;, &quot;Anzeiger für die Altertumswissenschaft&quot;, &quot;Atti della Accademia Ligure di Scienze e Lettere&quot;, &quot;Atti della Accademia di Scienze Morali e Politiche della Società Nazionale di Scienze, Lettere ed Arti di Napoli&quot;, &quot;Acta antiqua Academiae Scientiarum Hungaricae&quot;, &quot;Atti della Accademia Pontaniana&quot;, &quot;Atti della Accademia di Scienze, Lettere e Arti di Palermo. 2, Lettere&quot;, &quot;Atti e memorie dell&apos;Accademia Patavina di Scienze, Lettere ed Arti. 3, Memorie della Classe di Scienze Morali, Lettere ed Arti&quot;, &quot;Atti della Accademia Peloritana dei Pericolanti, Classe di Lettere, Filosofia e Belle Arti&quot;, &quot;Acta archaeologica&quot;, &quot;Acta archaeologica Academiae Scientiarum Hungaricae&quot;, &quot;Arheološki vestnik&quot;, &quot;Annales archéologiques arabes syriennes&quot;, &quot;Atti della Accademia Roveretana degli Agiati, Classe di Scienze umane, Classe di Lettere ed Arti&quot;, &quot;Jahrbuch Archäologie Schweiz&quot;, &quot;Annuaire d&apos;Archéologie Suisse&quot;, &quot;The Annual of the American Schools of Oriental Research&quot;, &quot;Atti della Accademia delle Scienze di Torino. 2, Classe di Scienze Morali, Storiche e Filologiche&quot;, &quot;Atti e memorie dell&apos;Accademia Toscana La Colombaria&quot;, &quot;Anzeiger der philosophisch-historischen Klasse / Österreichische Akademie der Wissenschaften Wien&quot;, &quot;Analecta Bollandiana&quot;, &quot;Archiv für Begriffsgeschichte&quot;, &quot;Annales de Bretagne et des Pays de l&apos;Ouest&quot;, &quot;The Annual of the British School at Athens&quot;, &quot;The Art Bulletin&quot;, &quot;Abhandlungen der Braunschweigischen Wissenschaftlichen Gesellschaft&quot;, &quot;L&apos;Antiquité classique&quot;, &quot;Acta classica Universitatis Scientiarum Debreceniensis&quot;, &quot;Annuaire du Collège de France&quot;, &quot;Acta classica&quot;, &quot;Acme&quot;, &quot;Acta Hyperborea&quot;, &quot;Ἀρχαιολογικὸν Δελτίον. Μελέτες&quot;, &quot;Adamantius&quot;, &quot;Annali del Dipartimento di Filosofia, Università di Firenze&quot;, &quot;Archivo español de arqueología&quot;, &quot;Aegyptus&quot;, &quot;Αρχείον οικονομικής ιστορίας&quot;, &quot;Archives of economic history&quot;, &quot;Ἀρχαιολογικὴ ἐφημερίς&quot;, &quot;Archaeologiai értesítő&quot;, &quot;Aestimatio&quot;, &quot;Aevum&quot;, &quot;Aevum antiquum&quot;, &quot;Anuari de filologia. Secció D, Studia Graeca et Latina&quot;, &quot;Anales de filología clásica&quot;, &quot;Annali della Facoltà di Giurisprudenza di Genova&quot;, &quot;Anuario filósofico&quot;, &quot;Annali della Facoltà di Lettere e Filosofia, Università degli Studi di Bari&quot;, &quot;Annali della Facoltà di Lettere e Filosofia dell&apos;Università di Cagliari&quot;, &quot;Annales de la Faculté des lettres et sciences humaines, Université Cheikh Anta Diop de Dakar&quot;, &quot;Annali della Facoltà di Lettere e Filosofia, Università di Macerata&quot;, &quot;Annali della Facoltà di Lettere e Filosofia dell&apos;Università di Napoli&quot;, &quot;Annali della Facoltà di Lettere e Filosofia di Perugia. 1, Studi classici&quot;, &quot;Annali della Facoltà di Lettere e Filosofia di Perugia. 4, Studi filosofici&quot;, &quot;Annali della Facoltà di Lettere e Filosofia di Perugia. 3, Studi linguistici e letterari&quot;, &quot;Annali della Facoltà di Lettere e Filosofia di Perugia. 2, Studi storico-antropologici&quot;, &quot;Annali della Facoltà di Lettere e Filosofia, Università di Siena&quot;, &quot;Annali della Faco
Dim mAbrev() As String
mAbrev = Array(&quot;A&amp;A&quot;, &quot;A&amp;Cr&quot;, &quot;A&amp;R&quot;, &quot;AA&quot;, &quot;AAAH&quot;, &quot;AABS&quot;, &quot;AAC&quot;, &quot;AAEC&quot;, &quot;AAHG&quot;, &quot;AALig&quot;, &quot;AAN&quot;, &quot;AAntHung&quot;, &quot;AAP&quot;, &quot;AAPal&quot;, &quot;AAPat&quot;, &quot;AAPel&quot;, &quot;AArch&quot;, &quot;AArchHung&quot;, &quot;AArchSlov&quot;, &quot;AArchSyr&quot;, &quot;AARov&quot;, &quot;AAS&quot;, &quot;AAS&quot;, &quot;AASO&quot;, &quot;AAT&quot;, &quot;AATC&quot;, &quot;AAWW&quot;, &quot;AB&quot;, &quot;ABG&quot;, &quot;ABPO&quot;, &quot;ABSA&quot;, &quot;ABull&quot;, &quot;ABWG&quot;, &quot;AC&quot;, &quot;ACD&quot;, &quot;ACF&quot;, &quot;AClass&quot;, &quot;Acme&quot;, &quot;ActaHyp&quot;, &quot;AD&quot;, &quot;Adamantius&quot;, &quot;ADFF&quot;, &quot;AEA&quot;, &quot;Aegyptus&quot;, &quot;AEH&quot;, &quot;AEH&quot;, &quot;AEph&quot;, &quot;AErt&quot;, &quot;Aestimatio&quot;, &quot;Aevum&quot;, &quot;Aevum(ant)&quot;, &quot;AFB&quot;, &quot;AFC&quot;, &quot;AFGG&quot;, &quot;AFilos&quot;, &quot;AFLB&quot;, &quot;AFLC&quot;, &quot;AFLD&quot;, &quot;AFLM&quot;, &quot;AFLN&quot;, &quot;AFLPer(class)&quot;, &quot;AFLPer(filos)&quot;, &quot;AFLPer(ling)&quot;, &quot;AFLPer(stor)&quot;, &quot;AFLS&quot;, &quot;AFMC&quot;, &quot;Africa&quot;, &quot;AFSFC&quot;, &quot;AGI&quot;, &quot;AGLComo&quot;, &quot;AGPh&quot;, &quot;AH&quot;, &quot;AHAM&quot;, &quot;AHAUSJ&quot;, &quot;AHB&quot;, &quot;AHB&quot;, &quot;AHC&quot;, &quot;AHDE&quot;, &quot;AHES&quot;, &quot;AHIg&quot;, &quot;AHistHung&quot;, &quot;AHMA&quot;, &quot;AHR&quot;, &quot;AIHS&quot;, &quot;AIIN&quot;, &quot;AIIS&quot;, &quot;AION(archeol)&quot;, &quot;AION(filol)&quot;, &quot;AION(ling)&quot;, &quot;AIPh&quot;, &quot;AIPhO&quot;, &quot;AIV&quot;, &quot;AJ&quot;, &quot;AJA&quot;, &quot;AJAH&quot;, &quot;AJN&quot;, &quot;AJPh&quot;, &quot;AK&quot;, &quot;AKB&quot;, &quot;AKBern&quot;, &quot;AKBern&quot;, &quot;AKG&quot;, &quot;Akroterion&quot;, &quot;Alba Regia&quot;, &quot;Alfinge&quot;, &quot;ALGP&quot;, &quot;ALMA&quot;, &quot;Altertum&quot;, &quot;AMal&quot;, &quot;AMAM(A)&quot;, &quot;AMAM(M)&quot;, &quot;AMAP&quot;, &quot;AMArc&quot;, &quot;AMAV&quot;, &quot;Ambix&quot;, &quot;AMSI&quot;, &quot;AMW&quot;, &quot;AN&quot;, &quot;Anabases&quot;, &quot;Anas&quot;, &quot;Anatolica&quot;, &quot;AncNarr&quot;, &quot;AncPhil&quot;, &quot;AncSoc&quot;, &quot;AncW&quot;, &quot;Anemos&quot;, &quot;Annales (HSS)&quot;, &quot;AnnNorm&quot;, &quot;AnnSE&quot;, &quot;Anregung&quot;, &quot;Anschnitt&quot;, &quot;AntAfr&quot;, &quot;Antichthon&quot;, &quot;Antiquity&quot;, &quot;AntJ&quot;, &quot;Antonianum&quot;, &quot;AntPhilos&quot;, &quot;AntTard&quot;, &quot;AOF&quot;, &quot;AOFL&quot;, &quot;AOrientHung&quot;, &quot;APapyrol&quot;, &quot;APB&quot;, &quot;Apeiron&quot;, &quot;APF&quot;, &quot;APhD&quot;, &quot;Apocrypha&quot;, &quot;Apollinaris&quot;, &quot;Aquila legionis&quot;, &quot;Aquitania&quot;, &quot;AR&quot;, &quot;Aram&quot;, &quot;Arcadia&quot;, &quot;Archaeologia&quot;, &quot;Archaeologiae&quot;, &quot;Archaeonautica&quot;, &quot;Archaiognosia&quot;, &quot;ArchClass&quot;, &quot;Archeologia&quot;, &quot;Architectura&quot;, &quot;ArchN&quot;, &quot;ArchOrient&quot;, &quot;ArchPhilos&quot;, &quot;ArchS&quot;, &quot;ArchS&quot;, &quot;Arctos&quot;, &quot;Arethusa&quot;, &quot;ARF&quot;, &quot;ARG&quot;, &quot;Argos&quot;, &quot;Ariadne&quot;, &quot;ARID&quot;, &quot;Arion&quot;, &quot;ARP&quot;, &quot;AS&quot;, &quot;ASAA&quot;, &quot;ASAE&quot;, &quot;ASCL&quot;, &quot;Asclepio&quot;, &quot;ASE&quot;, &quot;ASGM&quot;, &quot;ASGP&quot;, &quot;ASHF&quot;, &quot;ASMG&quot;, &quot;ASNP&quot;, &quot;ASP&quot;, &quot;ASR&quot;, &quot;ASSard&quot;, &quot;AStadt&quot;, &quot;Athena&quot;, &quot;Athenaeum&quot;, &quot;Atiqot&quot;, &quot;AU&quot;, &quot;AUB(class)&quot;, &quot;AUB(jur)&quot;, &quot;AUB(phil)&quot;, &quot;AUFG&quot;, &quot;Aufidus&quot;, &quot;AUFL&quot;, &quot;AUFS&quot;, &quot;AugStud&quot;, &quot;Augustiniana&quot;, &quot;Augustinianum&quot;, &quot;Augustinus&quot;, &quot;AUMLA&quot;, &quot;AUS&quot;, &quo
Dim oDocument As Object
Dim iReturnCode As Integer
If Check(mJournal) = 7 Then
Exit Sub
End If
iReturnCode = MsgBox(&quot;Cette macro vous permet d&apos;abréger les titres des revues citées en suivant les normes de l&apos;Année Philologique.&quot; &amp;_
vbNewLine &amp; vbNewLine &amp; &quot;Attention, il est recommandé d&apos;appliquer les normes de votre éditeur (éventuellement grâce à une macro dédiée) avant celles de l&apos;Année Philologique.&quot; &amp;_
vbNewLine &amp; vbNewLine &amp; &quot;Voulez-vous continuer ?&quot;,_
1, mJournal)
If iReturnCode = 2 Then
Exit Sub
Endif
oDocument = ThisComponent
Abbreviate (oDocument, mTitreLong(), mAbrev(), mJournal, bExpandFirstCitation)
End Sub
Function getOccurrencesCount(oScope As Object) As Variant
Const sZoteroItemIDRegex As String = &quot;&quot;&quot;itemData&quot;&quot;:\{&quot;&quot;id&quot;&quot;:[0-9]+&quot;
Const nZoteroItemIDCharsToIgnore As Integer = 17
Const sZoteroItemInfoRegex As String = &quot;[^}]+\}&quot;
Const nZoteroItemInfoCharsToIgnore As Integer = 2
Dim oZoteroNotes As Object
Dim sZoteroNoteContent As String
Dim iZoteroNote As Integer
Dim sItemIDRegex As String
Dim vIDBiblioNboccMap(0, 2) As Variant
Dim iMap As Integer
Dim oItemIDSearch As Object
Dim aIDSearchOptions As New com.sun.star.util.SearchOptions
Dim oItemInfoSearch As Object
Dim aInfoSearchOptions As New com.sun.star.util.SearchOptions
Dim aIDSearchResult As Object
Dim aTitleSearchResult As Object
Dim iItemIDMatch As Integer
Dim sItemID As String
Dim sItemInfo As String
Dim vSortedItemMap As Variant
oItemIDSearch = CreateUnoService(&quot;com.sun.star.util.TextSearch&quot;)
With aIDSearchOptions
.algorithmType = com.sun.star.util.SearchAlgorithms.REGEXP
.searchString = sZoteroItemIDRegex
End With
oItemIDSearch.setOptions(aIDSearchOptions)
oItemInfoSearch = CreateUnoService(&quot;com.sun.star.util.TextSearch&quot;)
With aInfoSearchOptions
.algorithmType = com.sun.star.util.SearchAlgorithms.REGEXP
.searchString = sZoteroItemInfoRegex
End With
oItemInfoSearch.setOptions(aInfoSearchOptions)
oZoteroNotes = oScope.getReferenceMarks()
For iZoteroNote = 0 To oZoteroNotes.getCount()-1
sZoteroNoteContent = oZoteroNotes.getByIndex(iZoteroNote).Name
aIDSearchResult = oItemIDSearch.searchForward(sZoteroNoteContent, 0, Len(sZoteroNoteContent)-1)
Do While aIDSearchResult.subRegExpressions &gt; 0
iItemIDMatch = aIDSearchResult.subRegExpressions - 1
sItemID = extractMatchingString(sZoteroNoteContent, aIDSearchResult, iItemIDMatch, nZoteroItemIDCharsToIgnore)
aTitleSearchResult = oItemInfoSearch.searchForward(sZoteroNoteContent, aIDSearchResult.endOffset(iItemIDMatch), Len(sZoteroNoteContent)-1)
sItemInfo = extractMatchingString(sZoteroNoteContent, aTitleSearchResult, 0, nZoteroItemInfoCharsToIgnore)
AddItemToMap(vIDBiblioNboccMap, sItemID, sItemInfo)
aIDSearchResult = oItemIDSearch.searchForward(sZoteroNoteContent, aIDSearchResult.endOffset(iItemIDMatch)+1, Len(sZoteroNoteContent)-1)
Loop
Next iZoteroNote
getOccurrencesCount = sortMapByNbOccurrences(vIDBiblioNboccMap)
End Function
Function getBibliographySection() As Object
Dim oTextSections As Object
Dim oTextSectionNames As Object
Dim iTextSection As Integer
Const sZoteroBibliographyID As String = &quot;ZOTERO_BIBL&quot;
On Error Goto
oTextSections = ThisComponent.getTextSections()
oTextSectionNames = oTextSections.getElementNames()
For iTextSection = 0 to UBound(oTextSectionNames)
If InStr(1, oTextSectionNames(iTextSection), sZoteroBibliographyID, 1) = 1 Then
getBibliographySection = oTextSections.getByIndex(iTextSection)
End If
Next iTextSection
End Function
Function getBibliographyCursor(sBibliographyHeaderStyle As String) As Object
Dim oSearch As Object
Dim oCursor As Object
oSearch = ThisComponent.createSearchDescriptor()
oSearch.SearchString = sBibliographyHeaderStyle
oSearch.SearchWords = TRUE
oSearch.SearchRegularExpression = FALSE
oSearch.SearchStyles = TRUE
On Error GoTo 0
oCursor = ThisComponent.Text.createTextCursorByRange(ThisComponent.findFirst(oSearch))
oCursor.collapseToEnd()
oCursor.gotoNextParagraph(False)
getBibliographyCursor = oCursor
End Function
Sub SetFontSlantToString(sString As String, vFontSlant As Variant)
Dim oDocument As Object
Dim oSearch As Object, oReplace As Object, oResult As Object
Dim oFound As Object, oFoundCursor As Object
Dim n As Integer
oDocument = ThisComponent
oSearch = oDocument.createSearchDescriptor
oReplace = oDocument.createReplaceDescriptor
oSearch.SearchString = sString
oSearch.SearchRegularExpression = FALSE
oSearch.SearchWords = TRUE
oSearch.SearchCaseSensitive = TRUE
oResult = oDocument.findAll(oSearch)
If oResult.count &gt; 0 Then
For n = 0 To oResult.count - 1
oFound = oResult.getByIndex(n)
oFoundCursor = oFound.Text.createTextCursorByRange(oFound)
oFoundCursor.CharPosture = vFontSlant
Next n
End If
End Sub
Sub SetFolioToPluralForm(sFolioSingular As String, sFolioPlural As String)
Dim sFolioFindRegex As String
sFolioFindRegex = &quot; &quot; &amp; sFolioSingular &amp; &quot;([0-9]+[rv]?)-&quot;
Dim sFolioReplaceRegex As String
sFolioReplaceRegex = &quot; &quot; &amp; sFolioPlural &amp; &quot;$1-&quot;
Dim oDocument As Object
Dim oSearch As Object, oReplace As Object, oResult As Object
oDocument = ThisComponent
oReplace = oDocument.createReplaceDescriptor
oReplace.SearchString = sFolioFindRegex
oReplace.SearchRegularExpression = TRUE
oReplace.SearchAll = TRUE
oReplace.ReplaceString = sFolioReplaceRegex
oDocument.replaceAll(oReplace)
End Sub
Sub RestoreNonBreakableSpaces &apos; Must be called before macros that involve formatting of the targeted strings.
Dim sStringsWithBreakableSpaceFirstSpace() As String
sStringsWithBreakableSpaceFirstSpace = Array(&quot; ;&quot;, &quot; :&quot;, &quot; !&quot;, &quot; ?&quot;)
Dim sStringsWithBreakableSpaceSecondSpace() As String
sStringsWithBreakableSpaceSecondSpace = Array(&quot; n. &quot;, &quot; no &quot;, &quot; nos &quot;, &quot; p. &quot;, &quot; f. &quot;, &quot; ff. &quot;, &quot; l. &quot;)
Dim oDocument As Object
Dim oReplace As Object, oResult As Object
Dim iString As Integer
Dim sStringToReplace As String
oDocument = ThisComponent
oReplace = oDocument.createReplaceDescriptor
For iString = 0 To UBound(sStringsWithBreakableSpaceFirstSpace)
sStringToReplace = sStringsWithBreakableSpaceFirstSpace(iString)
oReplace.SearchString = sStringToReplace
oReplace.SearchRegularExpression = FALSE
oReplace.SearchAll = TRUE
oReplace.ReplaceString = Replace(sStringToReplace, &quot; &quot;, &quot; &quot;) &apos; First space is breakable, second is non-breakable.
oDocument.replaceAll(oReplace)
Next iString
For iString = 0 To UBound(sStringsWithBreakableSpaceSecondSpace)
sStringToReplace = sStringsWithBreakableSpaceSecondSpace(iString)
oReplace.SearchString = sStringToReplace
oReplace.SearchRegularExpression = FALSE
oReplace.SearchAll = TRUE
oReplace.ReplaceString = &quot; &quot; &amp; Replace(sStringToReplace, &quot; &quot;, &quot; &quot;, 2) &apos; First space is breakable, second is non-breakable.
oDocument.replaceAll(oReplace)
Next iString
End Sub
Sub ReplaceString(sToReplace As String, sReplacement As String, bIsRegex As Boolean)
Dim oReplace As Object
oReplace = ThisComponent.createSearchDescriptor()
oReplace.SearchString = sToReplace
oReplace.SearchRegularExpression = bIsRegex
oReplace.ReplaceString = sReplacement
ThisComponent.replaceAll(oReplace)
End Sub
</script:module>