-
Notifications
You must be signed in to change notification settings - Fork 31
/
markdoc.ado
executable file
·3675 lines (2988 loc) · 163 KB
/
markdoc.ado
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
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// documentation is written for markdoc package (github.com/haghish/markdoc)
// . markdoc markdoc.ado, mini export(sthlp) replace
/***
_version 5.0.0_
markdoc
=======
__markdoc__ is a general-purpose literate programming package for Stata that
produces _dynamic analysis documents_, _presentation slides_, as well as Stata
package help files and package vignettes in various formats such as __pdf__,
__docx__, __html__, and __sthlp__.
for further information see:
- [markdoc homepage](http://haghish.com/markdoc)
- [journal article](https://journals.sagepub.com/doi/abs/10.1177/1536867X1601600409)
- [manual on Github wiki](https://github.com/haghish/markdoc/wiki)
- [package vignette (pdf)](https://github.com/haghish/markdoc/blob/master/vignette.pdf)
- [release notes on Github](https://github.com/haghish/markdoc/releases)
- [examples on GitHub](https://github.com/haghish/markdoc/tree/master/Examples)
- [please ask your questions on statalist.org](http://www.statalist.org/forums/forum/general-stata-discussion/general)
> from version _5.0_ forth, __markdoc__ is
{err}fully functional without any third-party software{txt}, due to its new
light-weight [mini engine](https://github.com/haghish/markdoc/wiki/mini). Yet,
a full installation of __markdoc__ and its dependencies is recommended.
Syntax
------
the syntax of the package is simple and can be summarized as:
> __markdoc__ _filename_ [, _options_ ]
where _filename_ can be:
| Document format | Description |
|-----------------|--------------------------------------------------------------------------------------------|
| __.do__ | executes _do_ file, examines the analysis reproducibility, and produces a dynamic document |
| __.smcl__ | converts _smcl_ file to a dynamic document without testing the code reproducibility |
| __.ado__ or __.mata__ | generates _sthlp_ help files or package vignettes from Markdown documentation |
### Options
the main options are the following:
| Option | Description |
|-------------------|--------------------------------------------------------------------------------------------------|
| mini | runs markdoc independent of any third-party software |
| statax | activates [statax](https://github.com/haghish/statax) syntax highlighter |
| replace | replaces exported document, if exists |
| **e**xport(_name_) | format; it can be __docx__, __pdf__, __html__, __sthlp__, __slide__, __md__, or __tex__ |
the supplementary options are the following:
| Option | Description |
|-------------------|--------------------------------------------------------------------------------------------------|
| **num**bered | numbers Stata commands in the dynamic document |
| date | adds the current date in the document |
| **tit**le(_str_) | specify the title of the document |
| **au**thor(_str_) | specify the author of the document |
| **aff**iliation(_str_) | specify the author affiliation in the document |
| **add**ress(_str_) | specify the author's contact information in the document |
| **sum**mary(_str_) | specify the summary of the document |
| **sty**le(_name_) | specify the style of the document; it can be __simple__, __stata__, or __formal__ |
options related to software documentation:
| Option | Description |
|-------------------|--------------------------------------------------------------------------------------------------|
| helplayout | appends a Markdown help layout template to a script file |
and the following options are for communicating with the third-party software (not required in the __mini__ mode)
| Option | Description |
|-------------------|--------------------------------------------------------------------------------------------------|
| **instal**l | installs the pandoc and wkhtmltopdf automatically, if they are not found |
| unc | specify that markdoc is being accessed from a Windows server with UNC file paths |
| **pan**doc(_str_) | specify the path to Pandoc software on the operating system |
| **print**er(_str_) | specify the path to pdf driver on the operating system |
| **mark**up(_name_) | specify the markup language used for notation; the default is Markdown |
| master | automatically creates the layout for LaTeX and HTML documents |
| template(_str_) | renders the document using an external style sheet file or example docx file |
| **t**est | examines markdoc third-party software with an example |
| toc | creates table of content |
Additional commands
-------------------
__markdoc__ includes a few commands that freatly simplify writing the workflow. you
may use the additioval commands to:
1. write dynamic text, while applying any display directive supported by the {help display} command:
> [__txt__](https://github.com/haghish/markdoc/wiki/txt) [_code_] [_display_directive_ [_display_directive_ [_..._]]]
2. capture and include the current image in the document automatically (if _filename_ is missing)
> [__img__](https://github.com/haghish/markdoc/wiki/img) [_filename_]
[, markup(_str_) **tit**le(_str_) **w**idth(_int_) **h**eight(_int_)
**m**arkup(_str_) left center ]
3. create and style a dynamic table in Markdown documents
> [__tbl__](https://github.com/haghish/markdoc/wiki/tbl) _(#[,#...] [\ #[,#...] [\ [...]]])_ [, **tit**le(_str_)]
furthermore, you can also call __pandoc__ or __wkhtmltopdf__ within Stata i.e. :
> [__pandoc__](https://github.com/haghish/markdoc/wiki/pandoc) _command_
> [__wkhtmltopdf__](https://github.com/haghish/markdoc/wiki/wkhtmltopdf) _command_
Installation
------------
The latest release as well as archived older versions of __markdoc__ are hosted on
[GitHub](https://github.com/haghish/markdoc) website. the recommended method
for installing the package is through [__github__ package](https://github.com/haghish/github)
package, which is used for building, searching, installing, and managing Stata
packages hosted on GitHub. you can install __github__ by typing:
. net install github, from("https://haghish.github.io/github/")
next, install the latest stable __markdoc__ release along with its Stata
dependencies by typing:
. github install haghish/markdoc, stable
Description
-----------
__markdoc__ is a general-purpose literate programming package for Stata that
produces _dynamic analysis documents_, _package vignette documentation_,
_dynamic presentation slides_, as well as dynamic _Stata package help files_.
to improve applications of the package for developing educational materials
and encouraging university lecturers to ask students to practice
literate programming for taking notes or doing their semester projects,
__markdoc__ was programmed to include unique features. These features make the package a
complete tool for documenting data analysis, Stata packages, as well as a tool for
producing educational materials within Stata Do-file editor. For example:
- it includes a syntax highlighter
- it recognizes markdown, html, and latex markup languages
- it can render LaTeX mathematical notations in __pdf__, __docx__, __html__, __odt__, and __tex__ documents
- it can automatically capture graphs from Stata and include them in the document
- it creates dynamic tables and supports writing dynamic text for interpretting the analysis
- it includes a user-friendly GUI interface (try __db markdoc__) to make using __markdoc__ easier for newbies.
Software Installation
---------------------
Without applying the __mini__ option, which uses the light-weight engine,
the markdoc package requires additional software which can be installed manually or
automatically. The required software are [Pandoc](http://pandoc.org/) and
[wkhtmltopdf](http://wkhtmltopdf.org). They are both
opensource freeware, supported for any common operating system such as Microsoft Windows,
Macintosh, and Linux. Naturally, users who wish to use LaTeX markup for writing
the documentation, will need a [pdfLaTeX](https://latex-project.org).
After a manual installation, the path to executable Pandoc should be specified in
__pandoc__ option. similarly, the path to executable wkhtmltopdf or pdfLaTeX
should be given to __printer__ option. Note that the __printer__ option
is only needed for compiling PDF document.
With automatic installation (i.e. using the __install__ option), Pandoc and
Wkhtmltopdf are downloaded and placed
in Weaver directory which is located in __/ado/plus/Weaver/__ on your machine. To find the
location of __ado/plus/__ directory on your machine use the
[sysdir](help sysdir) command which returns the system directories.
Set file paths permanently
--------------------------
After manual installation, the paths to the executable Pandoc, wkhtmltopdf,
and pdfLaTeX can be permanently set using __weave setup__ command. This command
will open _weaversetup.ado_ document, where you can define the files paths as global macros.
Software troubleshoot
---------------------
As mentioned, the required software can be installed manually or automatically.
The optional automatic installation is expected to
work properly in Microsoft Windows __XP__, Windows __7__, and Windows __8.1__, Macintosh
__OSX 10.9.5__, Linux __Mint 17 Cinnamon__ (32bit & 64bit), Ubuntu __14__ (64bit), and
__CentOS 7__ (64bit). Other operating systems may require manual software installation.
However, if for some technical or permission reasons markdoc fails to download, access, or run
Pandoc, install it manually and provide the
file path to Pandoc using __PANDOC__ option.
Calling Pandoc
--------------
[__PANDOC__](HELP PANDOC) commands can also be executed from Stata. This command takes the path to
the executable Pandoc from markdoc and allows you to use Pandoc seamlessly for converting
files within Stata. FOR EXAMPLE:
. pandoc ./example.tex -o ./example.html
Writing mathematical notation
-----------------------------
__markdoc__ can render LaTeX mathematical notations not only when the document
is exported to LaTeX __tex__, but also when the document is exported to
__pdf__ document or __slide__, Microsoft Office __docx__,
OpenOffice and LibreOffice __odt__, and __html__.
mathematical notations can be inline a text paragraph or on a separate line.
For writing inline notations, place the notation between single dollar signs,
for example: $a^2 + b^2 = c^2$
For including notation on a separate line, place the
notations between double dollar signs: $$a^2 + b^2 = c^2$$
Inserting an image or figure in the document
--------------------------------------------
Any of the supported markup languages can be used to insert a figure in the
document. In general, there are two ways for inserting an image in the document.
First, you can use Markdown, HTML, or LaTeX syntax for inserting an image -
that is already saved in your hard drive - in the document. The other solution
is using [__img__](https://github.com/haghish/markdoc/wiki/img) command.
__img__ command can take the _filename_ of exsisting image on the hard
drive and print the markup code (Markdown, HTML, or LaTeX. the default is
Markdown) int he document. __img__ command can also auto-export the current
graph and import it in the document. For more information in this regard see
the [__img__](https://github.com/haghish/markdoc/wiki/img).
Writing dynamic text
--------------------
the [__txt__](help txt) command is borrowed from {help weaver} package to print
dynamic text in the the exported dynamic document.
It can be used for interpreting the analysis results or dynamically referring to values of
scalars or macros in the dynamic document. Writing dynamic text allows the content of
the text to change by altering analysis codes and thus is the desirable way
for explaining the analysis results. The text and
macros can be styled using any of the supported markup languages in markdoc which are
_markdown_, _LaTeX_, and _HTML_. This command is fully documented on
[GitHub Wiki](https://github.com/haghish/markdoc/wiki/txt).
Creating dynamic tables with tbl command
----------------------------------------
the [__tbl__](help tbl) command also belongs
to [weaver](https://github.com/haghish/weaver) package. The syntax of this command
is similar to __matrix input__, however, it can include _string_, _digits_,
_scalars_, and _macros_ to create a dynamic table. This command is fully documented
on [__GitHub Wiki__](https://github.com/haghish/markdoc/wiki/tbl).
Markers
-------
__markdoc__ also introduces a few handy markers for annotating the
document, regardless of the markup language you use to write the document
(Markdown, Tex, HTML). These markers can be used to specify what
parts of the code should or should not appear in the dynamic document. The
table below provides a brief summary of these annotating markers. in general,
comments - unless they appear after a command - will be ignored in the dynamic
document. However, the markers mentioned below are _"special comments"_ that will
influence the markdoc process.
1. Creating text block
~~~
. /***
creates a block of comments in the smcl file that will be interpreted
in the dynamic document. this sign is distinguished from the normal comment
signs, with one star.
. ***/
~~~
2. Hiding command or output
~~~
. /**/ only include the output in the dynamic document and hide the comment
. /**/ only include the command in the dynamic document and hide the output
~~~
3. Hiding a section. Anything placed after __//OFF__ until __//ON__ markers will be _ignored_ in the dynamic document
~~~
. //OFF
Stata code
. //ON
~~~
4. Appending external text file (Markdown, HTML, LaTeX) to the dynamic document
~~~
. //IMPORT filename
~~~
Apart from the text block markers, the other markers _are not supported within loops_.
Nonetheless, writing markup text within the loop is not recommended either because
it only gets printed once. For active writing within the loop or a program, see the
{help txt} command.
Markers examples
----------------
### Example of riting text in the do-file
As noted, __markdoc__ package allows writing and styling text as a comment in
the do-file, using special comment signs. here is an example:
~~~
. /***
Text heading
============
subheading
----------
When you write a dynamic document in markdoc, place text between
the "/***" and "***/" signs. But they should be placed on separate lines,
as shown in this example.
. ***/
~~~
Dynamic Document Examples
-------------------------
~~~
qui log using example, replace
. /***
Introduction to markdoc (heading 1)
===================================
Using Markdown (heading 2)
--------------------------
Writing with __markdown__ syntax allows you to add text and graphs to
_smcl_ logfile and export it to a editable document format. I will demonstrate
the process by using the __Auto.dta__ dataset.
### Get started with markdoc (heading 3)
I will open the dataset, list a few observations, and export a graph.
Then I will export the logfile to Microsoft Office docx format.
. ***/
. /***/ sysuse auto, clear
. /**/ list in 1/5
. histogram price
. graph export graph.png, width(400) replace
. /***
Adding a graph or image in the report
======================================
Adding a graph using Markdown
-----------------------------
In order to add a graph using Markdown, I export the graph in PNG format.
You can explain the graph in the "brackets" and define the file path in parentheses
![explain the graph](./graph.png)
. ***/
~~~
When the log file is created, we can translate it with __markdoc__
~~~
. markdoc example, replace export(html) install
. markdoc example, replace export(docx)
. markdoc example, replace export(tex) master
. markdoc example, replace export(pdf)
. markdoc example, replace export(epub)
~~~
Dynamic Slide Examples
----------------------
this is an example of generating dynamic slides with __markdoc__
~~~
. qui log using example, replace
. /***
---
title:markdoc Dynamic Slides
author: E. F. Haghish
---
Slide 1
=======
- Writing with __markdown__ syntax allows you to add text and graphs
to _smcl_ logfile and export it to a editable document format. I will demonstrate
the process by using the __Auto.dta__ dataset.
- I will open the dataset, list a few observations, and export a graph.
Then I will export the logfile to Microsoft Office docx format.
Adding commands and output
==========================
. ***/
. sysuse auto, clear
. histogram price
. graph export graph.png, width(400) replace
. /***
Adding image in a slide
=======================
![Histogram of the price variable](./graph.png)
. ***/
. qui log c
. markdoc example, replace export(slide) install printer("/usr/texbin/pdflatex")
~~~
Supported markup languages
--------------------------
markdoc supports three markup languages which are Markdown, HTML, and LaTeX.
Markup languages should not be used together in one document because
__markdoc__ process each markup language differently.
Remarks
-------
If the log-file is closed exactly using __"qui log c"__ command, __markdoc__
automatically removes this command from the end of the file.
Similarly, markdoc removes __"qui log off"__ from the logfile. Therefore __"qui log off"__
and __"qui log on"__ can be used to separate codes in the dofile that are not wanted in the
dynamic document, but still required in for the analysis. Nonetheless, this is not a
proper practice and can harm the transparency of the analytic session. The log-file
should include as much information about the history of the analysis as possible.
Use the "Markers" for hiding sections of the log-file in the dynamic document.
Author
------
E. F. Haghish
University of Göttingen
[https://github.com/haghish](https://github.com/haghish)
See also
--------
- [Statax](https://github.com/haghish/statax), JavaScript & LaTeX syntax highlighter for Stata
License
-------
MIT License
- - -
This help file was dynamically produced by
[MarkDoc Literate Programming package](http://www.haghish.com/markdoc/)
***/
*cap prog drop markdoc
program markdoc
// -------------------------------------------------------------------------
// NOTE:
// Stata 14 introduces ustrltrim() function for removing Unicode whitespace
// characters and blanks. The previous trim() function cannot remove unicode
// whitespace. The program is updated to function for all versions of Stata,
// but yet, there is a slight chance of "unreliable" behavior from markdoc
// in older versions of Stata, if the string has a unicode whitespace. This
// can be fixed by finding a solution to avoid "ustrltrim()". Yet, most of
// the torture tests have been positive.
// =========================================================================
local version = int(`c(stata_version)')
if `version' <= 13 {
local trim trim
local version 11
}
if `version' > 13 {
local trim ustrltrim
local version 14
}
version `version'
// -------------------------------------------------------------------------
// WARNING
// =======
//
// Any change in the syntax should be also made in rundoc.ado and markdoc
// called by rundoc
// =========================================================================
syntax [anything(name=smclfile id="The smcl file name is")] ///
[, ///
replace /// replaces the exported file
mini /// runs markdoc independent of Pandoc and wkhtmltopdf
MARKup(name) /// specifies the markup language used in the document
Export(name) /// specifies the exported format
saving(str) /// UNDOCUMENTED
INSTALl /// Installs the required software automatically
Test /// tests the required software to make sure they're running correctly
PANdoc(str) /// specifies the path to Pandoc software on the machine
PRINTer(str) /// the path to the PDF printer on the machine
master /// creates a "Main" LaTeX & HTML layout
statax /// Activate the syntax highlighter
TEMPlate(str) /// template docx, CSS, ODT, or LaTeX heading
TITle(str) /// specifies the title of the document (for styling)
subtitle(str) /// specifies the subtitle (currently only for slides)
AUthor(str) /// specifies the author of mthe document (for styling)
AFFiliation(str) /// specifies author affiliation (for styling)
ADDress(str) /// specifies author contact information (for styling)
Date /// Add the current date to the document
SUMmary(str) /// writing the summary or abstract of the report
VERsion(str) /// add version to dynamic help file
STYle(name) /// specifies the style of the document
toc /// Creates table of content
build /// creates the toc and pkg files
NOIsily /// Debugging Pandoc, pdfLaTeX, and wkhtmltopdf
ASCIItable /// convert ASCII tables to SMCL in dynamic help files
NUMbered /// number Stata commands
helplayout /// create temporary help layout
unc /// an option for working with markdoc on servers
debug /// run the debug mode and save the temporary files
suppress /// UNDOCUMENTER, avoids unnecessary warnings
///
/// Slide options
/// ========================================================================
btheme(str) ///
bcolor(str) ///
bfont(str) ///
bfontsize(str) ///
bcodesize(str) ///
bwidth(str) ///
bheight(str) ///
/// DISCONTINUED SYNTAX
/// ========================================================================
MATHjax /// Interprets mathematics using MathJax
linesize(numlist max=1 int >=80 <=255) /// line size of the document and translator
TEXmaster /// creates a "Main" LaTeX file which is executable
///SETpath(str) /// the path to the PDF printer on the machine
///Printer(name) /// the printer name (for PDF only)
///TABle /// changes the formats of the table and creates publication ready tables (UNDER DEVELOPMENT AND UNDOCUMENTED)
///RUNhead(str) /// running head for the document (for styling)
///PDFlatex(str) ///this command is discontinued in version 3.0 and replaced by setpath()
///Font(name) /// specifies the document font (ONLY HTML)
]
// =========================================================================
// AVOID CRASHES by removing the working log from previous execution
// =========================================================================
macro drop currentmarkdocdofile
// =========================================================================
// CHANGED SYNTAX
// =========================================================================
local mathjax mathjax
if !missing("`mini'") {
if !missing("`markup'") {
if "`markup'" != "md" | "`markup'" != "markdown" | "`markup'" != "Markdown" {
display as err "{bf:`markup'} markup language is not supported in markdoc {bf:mini}"
}
}
}
if "`style'" == "" local style "simple"
if !missing("`texmaster'") {
di "The {bf:texmaster} option was renamed to {bf:master}, although it " ///
"continues to work..." _n
local master master
}
if !missing("`linesize'") {
di "The {bf:linesize} option is discontinued. {bf:markdoc} auto-detects " ///
"the linesize..." _n
local linesize
}
// =========================================================================
// check the path: make sure the file is executed from the working directory
// =========================================================================
if !missing("`mini'") {
local currentwd : pwd
capture abspath "`smclfile'"
if _rc != 0 capture abspath `smclfile'
if _rc == 0 {
if "`currentwd'" != "`r(path)'" {
if missing("`suppress'") di as err "{bf:WARNING}: make sure your source file is in your current working directory"
}
}
}
// -------------------------------------------------------------------------
// Check for Required Packages (Weaver & Statax)
// =========================================================================
capture findfile github.ado
if _rc != 0 {
if !missing("`install'") {
net install github, from("https://haghish.github.io/github/")
}
else {
display as err "github package is required: " ///
`"{ul:{stata net install github, from("https://haghish.github.io/github/"):net install github, from("https://haghish.github.io/github/")}}"' _n(2)
error 601
}
}
capture findfile weave.ado
if _rc != 0 {
if !missing("`install'") {
github install haghish/weaver
}
else {
capture findfile statax.js
if _rc != 0 {
display as err "weaver & statax packages are required: " _n ///
"{c 149} {ul:{stata github install haghish/weaver:github install haghish/weaver}}" _n ///
"{c 149} {ul:{stata github install haghish/statax:github install haghish/statax}}" ///
_n(2)
error 601
}
if _rc == 0 {
display as err "Weaver package is required: " ///
"{ul:{stata github install haghish/weaver:github install haghish/weaver}}" _n(2)
error 601
}
}
}
capture findfile statax.js
if _rc != 0 {
if !missing("`install'") {
github install haghish/statax
}
else {
display as err "statax package is required: " ///
"{ul:{stata github install haghish/statax:github install haghish/statax}}" _n(2)
error 601
}
}
// Run weaversetup
// -------------------------------------------------------------------------
capture program drop weaversetup //reload it
capture weaversetup //it might not be yet created
// Creating PDF slides with LaTeX Markup is the same as writing LaTeX PDF doc
// -------------------------------------------------------------------------
if "`export'" == "slide" & "`markup'" == "latex" {
local export pdf
}
// Creating html slides with for he light-weight markdoc mini
// -------------------------------------------------------------------------
if !missing("`mini'") & "`export'" == "slide" {
local export slidehtm
}
// Auto-correcting possible typos
// -------------------------------------------------------------------------
if "`markup'" == "HTML" local markup html
if "`markup'" == "LATEX" local markup latex
if "`markup'" == "Markdown" local markup markdown
if "`export'" == "markdown" local export md
if "`export'" == "PDF" local export pdf
if "`export'" == "HTML" local export html
if "`export'" == "LATEX" | "`export'" == "latex" local export tex
if "`export'" == "SMCL" local export smcl
if "`export'" == "STHLP" local export sthlp
if "`export'" == "latex" local export tex
// =========================================================================
// MINI MODE
//
// mini mode is used to avoid depending on third-party software. It currently
// only allows generating markdown documents and html documents in Stata 15.
// later on supports for docx and pdf will be provided
// -------------------------------------------------------------------------
if !missing("`mini'") {
if `c(stata_version)' < 15 & "`export'" != "sthlp" & "`export'" != "slidehtm" {
di as err "the {bf:mini} option requires Stata 15 or above"
di as txt "you could remove the {bf:mini} option and run markdoc in the full-version mode"
err 1
}
if "`export'" != "md" & "`export'" != "html" ///
& "`export'" != "docx" & "`export'" != "pdf" ///
& "`export'" != "sthlp" & "`export'" != "slidehtm" {
di as err "the {bf:mini} option currently only supports " ///
"{bf:md}, {bf:html}, {bf:docx}, {bf:pdf}, {bf:slide}, and {bf:sthlp} formats"
err 198
}
}
// =========================================================================
// Markup Language:
// check the markup language and the exported document format. If the
// format is not specified, alter the default if the "markup" is specified.
// check the output document for LaTeX and HTML markups and if the document
// does not match the markup language, return proper error
// =========================================================================
if "`markup'" == "html" {
if "`export'" != "html" & "`export'" != "pdf" & "`export'" != "xhtml" & ///
!missing("`export'") {
di as err "{p}The {bf:html} markup can only export {bf:html} " ///
"and {bf:pdf} documents"
error 100
}
if missing("`export'") local export html
}
if "`markup'" == "latex" {
if "`export'" != "tex" & "`export'" != "pdf" & !missing("`export'") {
di as err "{p}The {bf:latex} markup can only export {bf:tex} " ///
"and {bf:pdf} documents"
error 100
}
if missing("`export'") local export tex
}
// should markdoc be quiet?
// -------------------------------------------------------------------------
if missing("`noisily'") {
local cap cap
}
// The printer is used for creating PDF documents in markdoc. In general,
// there are 2 printers available which are "wkhtmltopdf" & "pdflatex."
// The default is "wkhtmltopdf"
// -------------------------------------------------------------------------
if "`export'" == "pdf" & "`markup'" != "latex" {
global printername "wkhtmltopdf" //printer for HTML and Markdown
if missing("`printer'") & !missing("$pathWkhtmltopdf") {
local printer "$pathWkhtmltopdf"
}
}
// should markdoc create a layout master?
// -------------------------------------------------------------------------
if !missing("`style'") | !missing("`statax'") | "`export'" == "pdf" {
if "`export'" == "pdf" | "`export'" == "html" {
local master master
}
}
if "`export'" == "tex" & !missing("`statax'") {
local master master
}
// =========================================================================
// pdfLaTeX
//
// This section does not install pdfLaTeX. But it attempts to find it
// on the users' operating system
// =========================================================================
if "`export'" == "pdf" & "`markup'" == "latex" & missing("`printer'") ///
| "`export'" == "slide" & missing("`printer'") {
global printername "pdflatex"
// look for weaversetup.ado
if !missing("$pathPdflatex") {
local printer "$pathPdflatex"
}
//be nice and search for it on their machines!
else {
// WINDOWS 32bit
// =============
// ???
// WINDOWS 64bit
// =============
if "`c(os)'" == "Windows" {
cap quietly findfile pdflatex.exe, ///
path("C:\Program Files\MiKTeX 2.9\miktex\bin\x64\")
if "`r(fn)'" != "" {
local printer "C:\Program Files\MiKTeX 2.9\miktex\bin\x64\pdflatex.exe"
}
}
// MACINTOSH
// =========
if "`c(os)'" == "MacOSX" {
cap quietly findfile pdflatex, path("/usr/texbin/")
if "`r(fn)'" != "" {
local printer "/usr/texbin/pdflatex"
}
}
// Unix
// ====
// ???
}
if missing("`printer'") {
di as txt "{p}(The {bf:printer} option is not defined, but " ///
"markdoc attempts to access pdfLaTeX automatically)" _n
display "(warning! pdfLaTeX not found...)"
//error 100
}
}
// =========================================================================
// STYLE
//
// markdoc applies a number of styles for HTML, PDF, and LaTeX documents
// The default style is "simple." Below the name of available styles is
// specified for each output format. The available styles are "simple"
// and "stata." The default style is "simple"
// =========================================================================
if "`style'" == "" local style "simple"
if "`export'" == "pdf" & "`style'" == "" local style "simple"
// CHECK FOR REQUIRED SOFTWARE
// -------------------------------------------------------------------------
//If PDF format is specified and pdf path is not empty, make sure file exists
if "`printer'" != "" {
confirm file "`printer'"
}
if !missing("`pandoc'") {
confirm file "`pandoc'"
global pandoc "`pandoc'"
}
else if missing("`pandoc'") & !missing("$pathPandoc") {
confirm file "$pathPandoc"
global pandoc "$pathPandoc"
}
// Print the path to pandoc
// -------------------------------------------------------------------------
if !missing("`noisily'") display _n(2) "{title:Pandoc path}" _n "$pandoc"
// checkes the required software
// -------------------------------------------------------------------------
if missing("`mini'") & "`export'" != "sthlp" & "`export'" != "slidehtm" {
markdoccheck , `install' `test' export(`export') style(`style') ///
markup(`markup') pandoc("$pandoc") printer("`printer'")
}
// -------------------------------------------------------------------------
// TEST markdoc
// =========================================================================
if "`test'" == "test" {
di _n(2)
di as txt "{hline}" _n
di as txt "{p}{ul: {bf:Running Example Do-file}}" _n
di as txt "{p}Running example.do from " ///
`"{browse "http://www.haghish.com/packages/markdoc/example.do":http://www.haghish.com/packages/markdoc/example.do}. "' ///
"Make sure you are {bf:connected to internet} and you " ///
"have permision to write and remove files in the current " ///
"working directory. " _n
do "http://www.haghish.com/packages/markdoc/example.do"
di _n(2)
di as txt "{hline}" _n
di as txt "{p}{ul: {bf:Running markdoc Test}}" _n
di as txt "{p}The example do-file is successfully executed. Next, " ///
"markdoc attempts to compile a HTML and PDF document" _n
markdoc example, export(html) statax replace ///
title(Testing markdoc Package) author(E. F. Haghish) ///
affiliation("Medical Biometry and Medical Informatics, " ///
"University of Freiburg") ///
address([email protected]) style(stata) pandoc("`pandoc'") ///
printer("`printer'") `noisily' `install'
markdoc example, export(pdf) statax replace ///
title(Testing markdoc Package) author(E. F. Haghish) ///
affiliation("Medical Biometry and Medical Informatics, " ///
"University of Freiburg") ///
address([email protected]) style(stata) pandoc("`pandoc'") ///
printer("`printer'") `noisily' `install'
cap quietly findfile "example.html"
if "`r(fn)'" != "" {
cap quietly findfile "example.pdf"
if "`r(fn)'" != "" {
display as txt "{p}{bf: markdoc works properly. " ///
"May The Source Be With You! ;)}" _n
}
}
di as txt "{hline}" _n
}
// -------------------------------------------------------------------------
// SYNTAX PROCESSING
// =========================================================================
// Syntax Highlighter
// -------------------------------------------------------------------------
if "`export'" != "html" & "`export'" != "pdf" & !missing("`statax'") ///
& "`export'" != "tex" {
if missing("`mini'") & "`export'" != "slide" {
display as txt "{p}(The {bf:statax} option is only used " ///
"when exporting to {bf:html}, {bf:pdf}, or {bf:tex} formats)" _n
local statax //Erase the macro
}
}
if !missing("`mini'") {
if "`export'" != "html" & "`export'" != "slidehtm" {
local statax
}
}
// PDF PROCESSING
// ==============
// Create a local for processing the PDF. Then change the export to HTML
// and later, change it to PDF using the "pdfhtml" local
if missing("`mini'") & "`export'" == "pdf" & "`markup'" != "latex" {
local pdfhtml "pdfhtml"
local export "html"
}
if "`export'" == "pdf" & "`markup'" == "latex" {
local pdftex "pdftex"
tempfile tex2pdf
//local export "tex"
}
/*
if !missing("`pdfhtml'") | !missing("`pdftex'") {
if !missing("`printer'") {
display as txt "{p}(The {bf:printer} option is only used " ///
"when exporting to {bf:pdf} format)" _n
//error 198
}
}
*/
if "`master'" != "" & "`export'" != "tex" & "`export'" != "pdf" & "`export'" != "html" {
di as txt "{p}(The {ul:{bf:master}} option should only be " ///
"specified while exporting to {bf:tex} or {bf:html} format)" _n
}
//Styles should be "simple" or "stata"
if "`style'" != "" & "`style'" != "stata" & "`style'" != "simple" ///
& "`style'" != "formal" & "`style'" != "empty" {
di as err "{p}{bf:style} option not recognized."
error 198
}
// make sure no problem happenes if the file has double quotation sign
capture local fname : display "`smclfile'"
if _rc != 0 {
capture local fname : display `smclfile'
if _rc == 0 {
local smclfile `fname'
}
}
// Use Absolute Path for UNC working directory
if c(os) == "Windows" & substr(c(pwd),1,2) =="\\\\" {
capture abspath "`smclfile'"
if _rc != 0 capture abspath `smclfile'
if _rc == 0 {
local smclfile `r(abspath)'
}
}
//If there is NO SMCL FILE and INSTALL or TEST options are not given,
//RETURN AN ERROR that the SMCL FILE IS NEEDED
if "`smclfile'" == "" & "`test'" == "" & "`install'" == "" {
di as txt _n(2) "{bf:markdoc requires...}" _n(2) ///
" smcl log-file to produce a dynamic document or PDF slides" _n ///
" {cmd:. markdoc {it:smclname}, [options]}" _n(2) ///
" do, ado, or mata file to produce dynamic Stata help files" _n ///
" {cmd:. markdoc {it:filename}, export(sthlp)}" _n(2) ///
" the {bf:test} option to test the required third-party software" _n ///
" {cmd:. markdoc, test}" _n(2) ///
"see {help markdoc} for more details"
exit 198
}
//Avoid Syntax Error for TEST and INSTALL options, when there is no
//SMCL file specified in the command. To do so, only run the engine