forked from Jonathan-LeRoux/IguanaTex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Macros.bas
684 lines (612 loc) · 24.8 KB
/
Macros.bas
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
Attribute VB_Name = "Macros"
Option Explicit
Public RegenerateContinue As Boolean
Sub NewLatexEquation()
Load LatexForm
Dim Sel As Selection
Set Sel = Application.ActiveWindow.Selection
If (Sel.Type = ppSelectionText) Then
LatexForm.textboxSize.Text = Sel.TextRange.Font.Size
End If
If IsEmpty(LatexForm.textboxSize.Text) Then
LatexForm.textboxSize.Text = "20"
End If
LatexForm.CheckBoxReset.Visible = False
LatexForm.Label2.Caption = "Set size:"
LatexForm.ButtonRun.Caption = "Generate"
#If Mac Then
LatexForm.ButtonRun.Accelerator = vbNullString
#Else
LatexForm.ButtonRun.Accelerator = "G"
#End If
LatexForm.textboxSize.Enabled = True
ShowLatexForm
End Sub
Private Sub ShowLatexForm()
Dim UseExternalEditor As Boolean
UseExternalEditor = GetITSetting("UseExternalEditor", False)
If UseExternalEditor Then
Dim TempFolder As String
Dim LatexCode As String
TempFolder = LatexForm.TextBoxTempFolder.Text
LatexCode = LatexForm.TextWindow1.Text
Load ExternalEditorForm
ExternalEditorForm.LaunchExternalEditor TempFolder, LatexCode
' LatexForm.Show vbModeless
' LatexForm.CmdButtonExternalEditor_Click
Else
LatexForm.Show vbModal
End If
End Sub
Sub EditLatexEquation()
' Check if the user currently has a single Latex equation selected.
' If so, display the dialog box. If not, dislpay an error message.
' Called when the user clicks the "Edit Latex Equation" menu item.
If Not TryEditLatexEquation() Then
MsgBox "You must select a single IguanaTex display to modify it."
End If
End Sub
Function TryEditLatexEquation() As Boolean
' Analyze the type of selected object to determine if it can be edited
Dim Sel As Selection
Set Sel = Application.ActiveWindow.Selection
Dim oldshape As Shape
If Sel.Type = ppSelectionShapes Then
' First make sure we don't have any shapes with duplicate names on this slide
DeDuplicateShapeNamesInSlide ActiveWindow.View.Slide.SlideIndex
If Sel.ShapeRange.count = 1 Then ' if not 1, then multiple objects are selected
If Sel.ShapeRange.Type = msoGroup Then
' Group case: either 1 object within a group, or 1 group corresponding to an EMF display
If Sel.HasChildShapeRange = False Then ' Maybe an EMF display
Set oldshape = Sel.ShapeRange(1)
TryEditLatexEquation = TryProcessShape(oldshape)
Exit Function
ElseIf Sel.ChildShapeRange.count = 1 Then
' 1 object inside a group
Set oldshape = Sel.ChildShapeRange(1)
TryEditLatexEquation = TryProcessShape(oldshape)
Exit Function
End If
Else
' Non-group case: only a single object can be selected
Set oldshape = Sel.ShapeRange(1)
If oldshape.Tags.Item("EMFchild") <> vbNullString Then
TryEditLatexEquation = False ' we should not have an EMF child object by itself
Else
TryEditLatexEquation = TryProcessShape(oldshape)
End If
Exit Function
End If
End If
End If
TryEditLatexEquation = False
End Function
Private Function TryProcessShape(oldshape As Shape) As Boolean
Dim LatexText As String
Dim j As Long
TryProcessShape = False
With oldshape.Tags
If .Item("LATEXADDIN") <> vbNullString Then ' we're dealing with an IguanaTex display
For j = 1 To .count
Debug.Print .Name(j) & vbTab & .value(j)
Next j
Load LatexForm
LatexText = .Item("LATEXADDIN")
LatexForm.RetrieveOldShapeInfo oldshape, LatexText
ShowLatexForm
TryProcessShape = True
Exit Function
ElseIf .Item("SOURCE") <> vbNullString Then ' we're dealing with a Texpoint display
For j = 1 To .count
Debug.Print .Name(j) & vbTab & .value(j)
Next j
Load LatexForm
LatexText = GetLatexTextFromTexPointShape(oldshape)
LatexForm.RetrieveOldShapeInfo oldshape, LatexText
ShowLatexForm
TryProcessShape = True
Exit Function
End If
End With
If TryProcessShape = False Then
'maybe a LatexIt display
LatexText = GetLatexTextFromLatexItShape(oldshape)
If LatexText <> vbNullString Then
' LatexIt display
oldshape.Tags.Add "BitmapVector", 0
LatexForm.RetrieveOldShapeInfo oldshape, LatexText
ShowLatexForm
TryProcessShape = True
Exit Function
End If
End If
End Function
' Make sure there aren't multiple shapes with the same name prior to processing
Private Sub DeDuplicateShapeNamesInSlide(SlideIndex As Integer)
Dim vSh As Shape
Dim vSl As Slide
Set vSl = ActivePresentation.Slides(SlideIndex)
Dim NameList() As String
Dim dict As New Dictionary
Dim n As Variant
Dim Key As String
For Each vSh In vSl.Shapes
If vSh.Type = msoGroup Then
NameList = CollectGroupedItemList(vSh, True)
Else
ReDim NameList(0 To 0) As String
NameList(0) = vSh.Name
End If
For n = LBound(NameList) To UBound(NameList)
Key = NameList(n)
If Not dict.Exists(Key) Then
dict.Item(Key) = 1
Else
dict.Item(Key) = dict.Item(Key) + 1
End If
Next n
Next vSh
For Each vSh In vSl.Shapes
Set dict = RenameDuplicateShapes(vSh, dict)
Next vSh
Set dict = Nothing
End Sub
Private Function RenameDuplicateShapes(vSh As Shape, dict As Dictionary) As Dictionary
If vSh.Type = msoGroup Then
Dim n As Long
For n = 1 To vSh.GroupItems.count
Set dict = RenameDuplicateShapes(vSh.GroupItems(n), dict)
Next
Else
Dim K As String
Dim shpCount As Long
K = vSh.Name
If dict.Item(K) > 1 Then
shpCount = 1
Do While dict.Exists(K & " " & shpCount)
shpCount = shpCount + 1
Loop
vSh.Name = K & " " & shpCount
dict.Add K & " " & shpCount, 1
End If
End If
Set RenameDuplicateShapes = dict
End Function
Public Sub RegenerateSelectedDisplays(Sel As Selection)
Dim vSh As Shape
Dim vSl As Slide
Dim SlideIndex As Integer
Dim DisplayCount As Long
RegenerateContinue = True
Select Case Sel.Type
Case ppSelectionShapes
' Regenerate 1 or more shapes on a single slide
SlideIndex = ActiveWindow.View.Slide.SlideIndex
DeDuplicateShapeNamesInSlide SlideIndex
DisplayCount = CountDisplaysInSelection(Sel)
If DisplayCount > 0 Then
RegenerateForm.LabelSlideNumber.Caption = 1
RegenerateForm.LabelTotalSlideNumber.Caption = 1
RegenerateForm.LabelShapeNumber.Caption = 0
RegenerateForm.LabelTotalShapeNumberOnSlide.Caption = DisplayCount
RegenerateForm.Show False
If Sel.HasChildShapeRange Then ' displays within a group
For Each vSh In Sel.ChildShapeRange
RegenerateOneDisplay vSh
Next vSh
Else
For Each vSh In Sel.ShapeRange
If vSh.Type = msoGroup And Not IsShapeDisplay(vSh) Then ' grouped displays
RegenerateGroupedDisplays vSh, SlideIndex
Else ' single display
RegenerateOneDisplay vSh
End If
Next vSh
End If
Else
MsgBox "No displays to be regenerated."
End If
Case ppSelectionSlides
' Regenerate all shapes on 1 or more slides
RegenerateForm.LabelSlideNumber.Caption = 0
RegenerateForm.LabelTotalSlideNumber.Caption = Sel.SlideRange.count
RegenerateForm.LabelShapeNumber.Caption = 0
RegenerateForm.LabelTotalShapeNumberOnSlide.Caption = 0
RegenerateForm.Show False
For Each vSl In Sel.SlideRange
RegenerateForm.LabelSlideNumber.Caption = RegenerateForm.LabelSlideNumber.Caption + 1
DisplayCount = CountDisplaysInSlide(vSl)
RegenerateForm.LabelTotalShapeNumberOnSlide.Caption = DisplayCount
DoEvents
If DisplayCount > 0 Then
RegenerateDisplaysOnSlide vSl
End If
Next vSl
Case Else
MsgBox "You need to select a set of shapes or slides."
End Select
With RegenerateForm
.Hide
.LabelShapeNumber.Caption = 0
.LabelSlideNumber.Caption = 0
.LabelTotalSlideNumber.Caption = 0
.LabelTotalShapeNumberOnSlide.Caption = 0
End With
Unload RegenerateForm
End Sub
Sub RegenerateDisplaysOnSlide(vSl As Slide)
vSl.Select
DeDuplicateShapeNamesInSlide vSl.SlideIndex
Dim vSh As Shape
For Each vSh In vSl.Shapes
If vSh.Type = msoGroup And Not IsShapeDisplay(vSh) Then
RegenerateGroupedDisplays vSh, vSl.SlideIndex
Else
RegenerateOneDisplay vSh
End If
Next vSh
End Sub
Sub RegenerateGroupedDisplays(vGroupSh As Shape, SlideIndex As Integer)
Dim n As Long
Dim vSh As Shape
Dim ItemToRegenerateList() As String
ItemToRegenerateList = CollectGroupedItemList(vGroupSh, False)
For n = LBound(ItemToRegenerateList) To UBound(ItemToRegenerateList)
Set vSh = ActivePresentation.Slides(SlideIndex).Shapes(ItemToRegenerateList(n))
RegenerateOneDisplay vSh
Next
End Sub
Private Function CollectGroupedItemList(vSh As Shape, AllDisplays As Boolean) As Variant
Dim n As Long
Dim j As Long
Dim prev_length As Long
Dim added_length As Long
Dim TmpList() As String
Dim SubList() As String
prev_length = -1
For n = 1 To vSh.GroupItems.count
If vSh.GroupItems(n).Type = msoGroup Then ' this case should never occur, as PPT disregards subgroups. Consider removing.
SubList = CollectGroupedItemList(vSh.GroupItems(n), AllDisplays)
added_length = UBound(SubList)
ReDim Preserve TmpList(0 To prev_length + added_length) As String
For j = prev_length + 1 To UBound(TmpList)
TmpList(j) = SubList(j - prev_length - 1)
Next j
prev_length = UBound(TmpList)
Else
If AllDisplays Or IsShapeDisplay(vSh.GroupItems(n)) Then
ReDim Preserve TmpList(0 To prev_length + 1) As String
TmpList(UBound(TmpList)) = vSh.GroupItems(n).Name
prev_length = UBound(TmpList)
End If
End If
Next
CollectGroupedItemList = TmpList
End Function
Sub RegenerateOneDisplay(vSh As Shape)
Dim LatexText As String
Dim DoneProcessingShape As Boolean
DoneProcessingShape = False
If RegenerateContinue Then
vSh.Select
With vSh.Tags
If .Item("LATEXADDIN") <> vbNullString Then ' we're dealing with an IguanaTex display
DoneProcessingShape = True
RegenerateForm.LabelShapeNumber.Caption = RegenerateForm.LabelShapeNumber.Caption + 1
DoEvents
Load LatexForm
LatexText = .Item("LATEXADDIN")
LatexForm.RetrieveOldShapeInfo vSh, LatexText
Apply_BatchEditSettings
LatexForm.ButtonRun_Click
Exit Sub
ElseIf .Item("SOURCE") <> vbNullString Then ' we're dealing with a Texpoint display
DoneProcessingShape = True
RegenerateForm.LabelShapeNumber.Caption = RegenerateForm.LabelShapeNumber.Caption + 1
DoEvents
Load LatexForm
LatexText = GetLatexTextFromTexPointShape(vSh)
LatexForm.RetrieveOldShapeInfo vSh, LatexText
Apply_BatchEditSettings
LatexForm.ButtonRun_Click
Exit Sub
End If
End With
If DoneProcessingShape = False Then
'maybe a LatexIt display
LatexText = GetLatexTextFromLatexItShape(vSh)
If LatexText <> vbNullString Then
' LatexIt display
DoneProcessingShape = True
vSh.Tags.Add "BitmapVector", 0
LatexForm.RetrieveOldShapeInfo vSh, LatexText
Apply_BatchEditSettings
LatexForm.ButtonRun_Click
Exit Sub
End If
End If
Else
Debug.Print "Pressed Cancel"
End If
End Sub
Private Function GetLatexTextFromLatexItShape(vSh As Shape) As String
Dim LatexText As String
LatexText = vbNullString
Dim TempPath As String
TempPath = CleanPath(LatexForm.TextBoxTempFolder.Text)
If Not IsPathWritable(TempPath) Then
MsgBox "The temporary folder is not writable, so we cannot test whether this display is a LatexIt display."
End If
Dim FilePrefix As String
FilePrefix = DefaultFilePrefix
Dim TimeOutTimeString As String
Dim TimeOutTime As Long
TimeOutTimeString = GetITSetting("TimeOutTime", "20") ' Wait N seconds for the processes to complete
TimeOutTime = val(TimeOutTimeString) * 1000
Dim debugMode As Boolean
debugMode = False
Dim RetVal As Long
Dim latexit_metadata_command As String
latexit_metadata_command = GetITSetting("LaTeXiT", DEFAULT_LATEXIT_METADATA_COMMAND)
Dim picPath As String
#If Mac Then
' On Windows, we check if the LaTeXiT metadata extractor exists, but unfortunately, if we do this on Mac,
' the Mac Sandbox asks us for permission to grant access to the executable, so we don't bother.
' Shape needs to be a picture, if so we save it as PDF
picPath = TempPath & FilePrefix & ".pdf"
If vSh.Type = msoPicture Then
'vSh.Export picPath, msoPictureTypePDF
Dim NewPres As Presentation
Set NewPres = Presentations.Add(msoFalse)
Dim NewSlide As Slide
Set NewSlide = NewPres.Slides.Add(index:=1, Layout:=ppLayoutBlank)
Dim NewShape As Shape
vSh.Copy
NewPres.Slides(1).Shapes.Paste
' This briefly displays a saving progress dialog, but I haven't found a way to disable that
NewPres.SaveAs picPath, ppSaveAsPDF
'Application.DisplayAlerts = True
NewPres.Close
Set NewPres = Nothing
End If
Dim fs As New MacFileSystemObject
#Else
' no need to go through all this trouble if the user does not have the LaTeXiT metadata extractor...
Dim fs As New FileSystemObject
If fs.FileExists(latexit_metadata_command) Then
' Shape needs to be a picture, if so we save it as EMF
picPath = vbNullString
If vSh.Type = msoPicture Then
' Unfortunately, saving as EMF corrupts the EMF file and loses the LaTeXiT info
'vSh.Export picPath, ppShapeFormatEMF
' So, we need to use a more complicated route...
Dim NewPres As Presentation
Set NewPres = Presentations.Add(msoFalse)
Dim NewSlide As Slide
Set NewSlide = NewPres.Slides.Add(index:=1, Layout:=ppLayoutBlank)
Dim NewShape As Shape
vSh.Copy
NewPres.Slides(1).Shapes.Paste
Dim FilePrefixLatexit As String
FilePrefixLatexit = TempPath & FilePrefix & "_latexit"
NewPres.SaveAs (FilePrefixLatexit & ".pptx")
NewPres.Close
Set NewPres = Nothing
fs.CopyFile FilePrefixLatexit & ".pptx", FilePrefixLatexit & ".zip", True
fs.DeleteFile FilePrefixLatexit & ".pptx"
Dim Image1EMF As String
Image1EMF = "ppt\media\image1.emf"
RetVal& = Execute("unzip -o " & FilePrefixLatexit & ".zip" & " " & Image1EMF _
& " -d " & FilePrefixLatexit, TempPath, debugMode, TimeOutTime)
If fs.FileExists(FilePrefixLatexit & ".zip") Then
fs.DeleteFile FilePrefixLatexit & ".zip"
End If
If fs.FileExists(FilePrefixLatexit & "\" & Image1EMF) Then
fs.CopyFile FilePrefixLatexit & "\" & Image1EMF, FilePrefixLatexit & ".emf"
picPath = FilePrefixLatexit & ".emf"
End If
If fs.FolderExists(FilePrefixLatexit) Then
fs.DeleteFolder FilePrefixLatexit
End If
End If
End If
#End If
' Run LatexIt metadata extractor
If fs.FileExists(picPath) Then
Dim RunCommand As String
RunCommand = ShellEscape(latexit_metadata_command) & " " & picPath
RetVal& = Execute(RunCommand, TempPath, debugMode, TimeOutTime)
If (RetVal& <> 0) Then
Dim ErrorMessage As String
ErrorMessage = "LatexIt Metadata extraction did not run properly, please make sure it runs on the command line."
ShowError ErrorMessage, RunCommand
Else
If fs.FileExists(picPath & ".tex") Then
LatexText = ReadAll(picPath & ".tex")
If Len(LatexText) > 16 Then
vSh.Tags.Add "IGUANATEXCURSOR", Len(LatexText) - 16
End If
fs.DeleteFile picPath & ".tex"
End If
If fs.FileExists(picPath) Then fs.DeleteFile picPath
End If
End If
GetLatexTextFromLatexItShape = LatexText
End Function
Private Function GetLatexTextFromTexPointShape(vSh As Shape) As String
Dim LatexText As String
Dim SourceParts() As String
Dim TeXSource As String
Dim ScalingFactor As Single
Dim IsTemplate As Boolean
With vSh.Tags
ScalingFactor = 1
IsTemplate = False
If .Item("ORIGWIDTH") <> vbNullString Then
ScalingFactor = ScalingFactor * vSh.Width / val(.Item("ORIGWIDTH"))
End If
If .Item("TEXPOINT") = "template" Then
IsTemplate = True
End If
vSh.Tags.Add "TEXPOINTSCALING", ScalingFactor
If IsTemplate = True Then
SourceParts = Split(.Item("SOURCE"), vbTab, , vbTextCompare)
If UBound(SourceParts) > 2 Then
TeXSource = SourceParts(3)
Else
SourceParts = Split(.Item("SOURCE"), "equation", , vbTextCompare)
SourceParts = Split(SourceParts(1), "template TP", , vbTextCompare)
TeXSource = SourceParts(0)
End If
LatexText = DEFAULT_LATEX_CODE_PRE & "$" & TeXSource & "$" & DEFAULT_LATEX_CODE_POST
vSh.Tags.Add "IGUANATEXCURSOR", Len(LatexText) - 16
Else
LatexText = .Item("SOURCE")
End If
Dim j As Long
For j = 1 To .count
Debug.Print .Name(j) & vbTab & .value(j)
Next j
End With
GetLatexTextFromTexPointShape = LatexText
End Function
Private Sub Apply_BatchEditSettings()
If BatchEditForm.CheckBoxModifyEngine.value Then
LatexForm.ComboBoxLaTexEngine.ListIndex = BatchEditForm.ComboBoxLaTexEngine.ListIndex
End If
If BatchEditForm.CheckBoxModifyTempFolder.value Then
LatexForm.TextBoxTempFolder.Text = BatchEditForm.TextBoxTempFolder.Text
End If
If BatchEditForm.CheckBoxModifyBitmapVector.value Then
LatexForm.ComboBoxBitmapVector.ListIndex = BatchEditForm.ComboBoxBitmapVector.ListIndex
End If
If BatchEditForm.CheckBoxModifyLocalDPI.value Then
LatexForm.TextBoxLocalDPI.Text = BatchEditForm.TextBoxLocalDPI.Text
End If
If BatchEditForm.CheckBoxModifySize.value Then
LatexForm.CheckBoxReset.value = True
LatexForm.textboxSize.Text = BatchEditForm.textboxSize.Text
End If
If BatchEditForm.CheckBoxForcePreserveSize.value Then
LatexForm.CheckBoxForcePreserveSize.value = True
End If
If BatchEditForm.CheckBoxModifyTransparency.value Then
LatexForm.checkboxTransp.value = BatchEditForm.checkboxTransp.value
End If
If BatchEditForm.CheckBoxModifyResetFormat.value Then
LatexForm.CheckBoxResetFormat.value = BatchEditForm.CheckBoxResetFormat.value
End If
If BatchEditForm.CheckBoxReplace.value Then
If BatchEditForm.TextBoxFind.Text <> vbNullString Then
LatexForm.TextWindow1.Text = Replace(LatexForm.TextWindow1.Text, BatchEditForm.TextBoxFind.Text, BatchEditForm.TextBoxReplacement.Text)
End If
End If
End Sub
Function IsShapeDisplay(vSh As Shape) As Boolean
IsShapeDisplay = False
With vSh.Tags
If .Item("LATEXADDIN") <> vbNullString Then ' we're dealing with an IguanaTex display
IsShapeDisplay = True
ElseIf .Item("SOURCE") <> vbNullString Then ' we're dealing with a Texpoint display
IsShapeDisplay = True
ElseIf GetLatexTextFromLatexItShape(vSh) <> vbNullString Then ' we're dealing with a LatexIt display
IsShapeDisplay = True
End If
End With
End Function
Function CountDisplaysInShape(vSh As Shape) As Integer
Dim DisplayCount As Long
DisplayCount = 0
If vSh.Type = msoGroup Then ' grouped displays
Dim s As Shape
For Each s In vSh.GroupItems
DisplayCount = DisplayCount + CountDisplaysInShape(s)
Next
Else ' single display
If IsShapeDisplay(vSh) Then
DisplayCount = 1
End If
End If
CountDisplaysInShape = DisplayCount
End Function
Function CountDisplaysInSelection(Sel As Selection) As Integer
Dim vSh As Shape
Dim DisplayCount As Long
DisplayCount = 0
If Sel.HasChildShapeRange Then ' displays within a group
For Each vSh In Sel.ChildShapeRange
DisplayCount = DisplayCount + CountDisplaysInShape(vSh)
Next vSh
Else
For Each vSh In Sel.ShapeRange
DisplayCount = DisplayCount + CountDisplaysInShape(vSh)
Next vSh
End If
CountDisplaysInSelection = DisplayCount
End Function
Function CountDisplaysInSlide(vSl As Slide) As Integer
Dim vSh As Shape
Dim DisplayCount As Long
DisplayCount = 0
For Each vSh In vSl.Shapes
DisplayCount = DisplayCount + CountDisplaysInShape(vSh)
Next vSh
CountDisplaysInSlide = DisplayCount
End Function
Private Sub Auto_Open()
' Runs when the add-in is loaded
LatexForm.InitializeApp
Load LatexForm
Unload LatexForm
End Sub
Private Sub Auto_Close()
LatexForm.UnInitializeApp
End Sub
Public Sub RegenerateSelection()
Load BatchEditForm
BatchEditForm.Show
End Sub
Public Sub ConvertToVector()
Load BatchEditForm
BatchEditForm.CheckBoxModifyBitmapVector.value = True
BatchEditForm.ComboBoxBitmapVector.Enabled = True
BatchEditForm.ComboBoxBitmapVector.ListIndex = 1
BatchEditForm.CheckBoxModifyPreserveSize.value = True
BatchEditForm.CheckBoxForcePreserveSize.Enabled = True
BatchEditForm.CheckBoxForcePreserveSize.value = True
BatchEditForm.ButtonRun_Click
End Sub
Public Sub ConvertToBitmap()
Load BatchEditForm
BatchEditForm.CheckBoxModifyBitmapVector.value = True
BatchEditForm.ComboBoxBitmapVector.Enabled = True
BatchEditForm.ComboBoxBitmapVector.ListIndex = 0
BatchEditForm.CheckBoxModifyPreserveSize.value = True
BatchEditForm.CheckBoxForcePreserveSize.Enabled = True
BatchEditForm.CheckBoxForcePreserveSize.value = True
BatchEditForm.ButtonRun_Click
End Sub
Public Sub LoadSettingsForm()
Load SetTempForm
SetTempForm.Show
End Sub
Public Sub InsertVectorGraphicsFile()
Load LoadVectorGraphicsForm
LoadVectorGraphicsForm.ButtonPath_Click
LoadVectorGraphicsForm.Show
End Sub
Public Sub TestError()
Dim ErrorMessage As String
ErrorMessage = "latex did not return in 60 seconds and may have hung." _
& vbNewLine & "Please make sure your code compiles outside IguanaTex." _
& vbNewLine & "You may also try generating in Debug mode, as it will let you know if any font/package is missing."
Dim LastCommand As String
Dim TeXExePath As String, TeXExeExt As String
TeXExePath = GetITSetting("TeXExePath", DEFAULT_TEX_EXE_PATH)
TeXExeExt = vbNullString
Dim FilePrefix As String
FilePrefix = DefaultFilePrefix
LastCommand = ShellEscape(TeXExePath & "pdflatex" & TeXExeExt) & " -shell-escape -output-format dvi -interaction=batchmode " _
& FilePrefix & ".tex"
ShowError ErrorMessage, LastCommand
End Sub