Skip to content

Commit 57c881e

Browse files
authored
Merge pull request #48 from texmacs/develop
Minor updates
2 parents dce23ec + 5150813 commit 57c881e

File tree

11 files changed

+1078
-270
lines changed

11 files changed

+1078
-270
lines changed

CONTRIBUTING.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Contributing to the TeXmacs markdown plugin
2+
3+
Follow the setup instructions in [README.md](README.md) to get started.
4+
5+
**TODO:** this document is a stub.
6+
7+
## Code organization
8+
9+
Conversion is done in two stages:
10+
11+
1. From TeXmacs to an internal stree representation: `tmmarkdown.scm`.
12+
2. From the internal representation to markdown: `markdownout.scm`.
13+
14+
The plugin is loaded in `init-markdown.scm`, and some utilities are provided in
15+
`markdown-utils.scm`. Extensions to TeXmacs menus are in `markdown-menus.scm`.
16+
17+
Tests are in `tests/` and are can be run from within TeXmacs with the markdown
18+
menu.
19+
20+
## Conversion from TeXmacs to internal representation
21+
22+
The entry point is `tm->markdown*` in `tmmarkdown.scm`. The function takes a
23+
TeXmacs tree and returns an slist of markdown elements. This is also a
24+
pre-processing step does things like dropping TeXmacs-specific info, adding
25+
labels to equations, setting up counters, etc.
26+
27+
Parsing functions always return an slist. Some arguments are processed and
28+
`tm->markdown*` is typically called on the remaining ones recursively.
29+
30+
31+
## Conversion from internal representation to markdown
32+
33+
The entry point is `serialize-markdown` in `markdownout.scm`.
34+
35+
## Some suggestions for development
36+
37+
Like all TeXmacs code, the entry point for each module is located at the
38+
bottom of the file.
39+
40+
Scheme sessions inside TeXmacs documents are very useful to prototype ideas.
41+
First you want to add whatever tag it is that you are interested, say `mytag`
42+
to the top of the document, then you read it into scheme with:
43+
44+
```scheme
45+
(select (buffer-get-body (current-buffer)) '(:* mytag))
46+
```
47+
48+
This will return a list of trees with the tag `mytag`. You can then pick any
49+
one of them and process it with the `tm-` prefixed built-in functions:
50+
* `(tm-ref x pos)`: returns the `pos`th child of `x`.
51+
* `(tm->string x)`: returns a string representation of `x`.
52+
* `(tm->markdown* x)`: returns an slist of markdown elements.
53+
54+
## Testing
55+
56+
Tests are located in `tests/` and are run from within TeXmacs with the markdown
57+
menu. Each test reads a TeXmacs file and compares it with a homonymous markdown
58+
file in the same directory.

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,18 @@ possibility of exporting them as html into the markdown file.
99

1010
The plugin has been developed for its use in two specific websites,
1111
[Paperwhy](https://paperwhy.8027.org/) and appliedAI's
12-
[TransferLab](https://transferlab.appliedai.de/), and can use multiple
13-
extensions specific to the static website generator [Hugo](https://gohugo.io/).
14-
There might still be some code very specific to those sites, YMMV.
12+
[TransferLab](https://transferlab.ai/), and can use multiple extensions
13+
specific to the static website generator [Hugo](https://gohugo.io/). There
14+
might still be some code very specific to those sites, YMMV.
1515

1616
## Setup
1717

18-
Clone this repository into your `~/.TeXmacs/plugins` directory as `markdown`.
19-
For Linux / OSX this is:
18+
Clone this repository into your `~/.TeXmacs/plugins` directory as `markdown`
19+
and checkout the `master` branch. For Linux / OSX this is:
2020

2121
```shell
22-
git clone https://github.com/texmacs/markdown.git ~/.TeXmacs/plugins/markdown
22+
git clone -b master https://github.com/texmacs/markdown.git
23+
~/.TeXmacs/plugins/markdown
2324
```
2425

2526
For Windows, the path (usually?) is
@@ -55,7 +56,9 @@ package -> Markdown -> markdown` to enable:
5556

5657
* Support for alternate image formats between TeXmacs and markdown via
5758
`<md-alt-image|tm-image|md-image>`. This is useful e.g. to provide
58-
SVG and EPS/PDF versions of images for print and web respectively.
59+
SVG and EPS/PDF versions of images for print and web respectively. The same
60+
effect can be achieved with `<specific|markdown|…>` and
61+
`<specific|texmacs|…>`.
5962
* Macros for labels in equation arrays. Using positioning tricks with
6063
`<htab>` results in LaTeX code that MathJax does not support, namely
6164
`\hfill`. For this reason, we provide two macros
@@ -107,7 +110,11 @@ All custom shortcodes are in `extensions/hugo/`.
107110

108111
* Figures are converted to `{{< figure >}}`.
109112
* For arbitrary shortcodes, use `<hugo-short>`, e.g.
110-
`<hugo-short|toc>` for `{{< toc >}}`.
113+
`<hugo-short|toc>` for `{{< toc >}}`. In order to pass
114+
named arguments, use
115+
`<hugo-short|shortcode-name|argname1|argvalue1|…>`. For
116+
positional arguments, replace the argument names by `#f` as in
117+
`<hugo-short|shortcode-name|#f|posvalue1|#f|posvalue2|…>`.
111118
* Citations using `<cite>` and `<cite-detail>` (of any arity)
112119
are automatically detected and converted to `{{< cite ref >}}`, and
113120
all of them are gathered in the frontmatter as well, for indization by Hugo's

doc/markdown.en.tm

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
<TeXmacs|2.1>
1+
<TeXmacs|2.1.2>
22

33
<style|tmdoc>
44

55
<\body>
6-
<tmdoc-title|Markdown plug-in>
6+
<specific|texmacs|<tmdoc-title|Markdown plug-in>>
77

88
<section|<TeXmacs> markdown plugin>
99

@@ -16,18 +16,19 @@
1616

1717
The plugin has been developed for its use in two specific websites,
1818
<hlink|Paperwhy|https://paperwhy.8027.org/> and appliedAI's
19-
<hlink|TransferLab|https://transferlab.appliedai.de/>, and can use multiple
19+
<hlink|TransferLab|https://transferlab.ai/>, and can use multiple
2020
extensions specific to the static website generator
2121
<hlink|Hugo|https://gohugo.io/>. There might still be some code very
2222
specific to those sites, YMMV.
2323

2424
<subsection|Setup>
2525

2626
Clone this repository into your <shell|~/.TeXmacs/plugins> directory as
27-
<shell|markdown>. For Linux / OSX this is:
27+
<shell|markdown> and checkout the <shell|master> branch. For Linux / OSX
28+
this is:
2829

2930
<\shell-code>
30-
git clone https://github.com/texmacs/markdown.git
31+
git clone -b master https://github.com/texmacs/markdown.git
3132
~/.TeXmacs/plugins/markdown
3233
</shell-code>
3334

@@ -73,7 +74,9 @@
7374
<item>Support for alternate image formats between <TeXmacs> and markdown
7475
via <explain-macro|md-alt-image|tm-image|md-image>. This is useful e.g.
7576
to provide SVG and EPS/PDF versions of images for print and web
76-
respectively.
77+
respectively. The same effect can be achieved with
78+
<explain-macro|specific|markdown|<text-dots>> and
79+
<explain-macro|specific|texmacs|<text-dots>>.
7780

7881
<item>Macros for labels in equation arrays. Using positioning tricks with
7982
<explain-macro|htab> results in <LaTeX> code that <name|MathJax> does not
@@ -143,7 +146,10 @@
143146
\<gtr\>}}>.
144147

145148
<item>For arbitrary shortcodes, use <explain-macro|hugo-short>, e.g.
146-
<explain-macro|hugo-short|toc> for <code*|{{\<less\> toc \<gtr\>}}>.
149+
<explain-macro|hugo-short|toc> for <code*|{{\<less\> toc \<gtr\>}}>. In
150+
order to pass named arguments, use <explain-macro|hugo-short|shortcode-name|argname1|argvalue1|<text-dots>>.
151+
For positional arguments, replace the argument names by <tt|#f> as in
152+
<explain-macro|hugo-short|shortcode-name|#f|posvalue1|#f|posvalue2|<text-dots>>.
147153

148154
<item>Citations using <explain-macro|cite> and
149155
<explain-macro|cite-detail> (of any arity) are automatically detected and
@@ -189,4 +195,4 @@
189195
<\collection>
190196
<associate|markdown-auto-export|../README.md>
191197
</collection>
192-
</initial>
198+
</initial>

packages/markdown/hugo.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<TeXmacs|2.1>
1+
<TeXmacs|2.1.2>
22

33
<style|source>
44

@@ -28,6 +28,8 @@
2828
</src-comment>
2929
</active*>
3030

31+
<assign|hugo-short|<xmacro|args|<flag|<merge|hugo-|<arg|args|0>>|green>>>
32+
3133
<assign|hugo-front|<xmacro|args|<flag|frontmatter parameters|orange>>>
3234

3335
<assign|dict|<xmacro|kvs|dict (to do: display keys and values)>>

progs/markdown-menus.scm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,8 @@
102102
(menu-bind texmacs-extra-menu
103103
(if (and (supports-markdown?) (markdown-menu-show?))
104104
(=> "Markdown" (link markdown-menu))))
105+
106+
(menu-bind specific-menu
107+
(when (not (selection-active-large?))
108+
(former)
109+
("Markdown" (make-specific "markdown"))))

progs/markdownout.scm

Lines changed: 78 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,9 @@
136136
(define (md-abstract x)
137137
(if (hugo-extensions?)
138138
(with-md-globals 'paragraph-width #f
139-
(with-md-globals 'disable-shortcodes #t
140-
(md-hugo-frontmatter
139+
(md-hugo-frontmatter
141140
`(hugo-front "summary" ,(serialize-markdown* (cdr x))))))
142-
(md-paragraph `(concat (strong "Abstract: ") (em ,(cdr x))))))
141+
(md-paragraph `(concat (strong "Abstract: ") (em ,(cdr x)))))
143142

144143
(define (must-adjust? t)
145144
(tm-in? t '(strong em tt strike math concat cite cite-detail
@@ -394,7 +393,7 @@
394393
(with citations
395394
(filter (lambda (x) (and (string? x) (not (string-null? x)))) (cdr x))
396395
(md-set 'refs (append (md-get 'refs) citations))
397-
(md-hugo-shortcode
396+
(md-hugo-shortcode*
398397
(cons 'cite (map (lambda (s) `(#f . ,s)) citations))))))
399398

400399
(define (md-cite-detail x)
@@ -423,8 +422,8 @@
423422
(begin
424423
(set! args (assoc-remove-many args '(body name caption)))
425424
(set! args (assoc-append? args 'class (md-get 'html-class)))
426-
(md-hugo-shortcode `(,type ,@args)
427-
`(document ,body (concat ,name ,caption))))
425+
(md-hugo-shortcode* `(,type ,@args)
426+
`(document ,body (concat ,name ,caption))))
428427
(with content (if (assoc 'src args)
429428
`(image ,(assoc-ref args 'src) ,body)
430429
body)
@@ -464,7 +463,12 @@
464463
(map set-pair! (list->assoc (cdr x))))))
465464
"")
466465

467-
(define (md-hugo-shortcode x . inner)
466+
(define (md-hugo-shortcode x)
467+
"Processes '(hugo-short shortcode-name (args)) where args is a list of tuples (name val). For unnamed arguments, use (#f val)"
468+
(md-hugo-shortcode* (cdr x)))
469+
470+
(define (md-hugo-shortcode* x . inner)
471+
"Inner processing of shortcodes"
468472
(if (not (md-get 'disable-shortcodes))
469473
(let ((shortcode (symbol->string (car x)))
470474
(args (cdr x))
@@ -485,14 +489,14 @@
485489

486490
(define (md-bibliography x)
487491
(if (hugo-extensions?)
488-
(md-hugo-shortcode '(references))
492+
(md-hugo-shortcode* '(references))
489493
(md-style '(strong "Bibliography not implemented for raw Markdown"))))
490494

491495
(define (md-sidenote-sub x numbered?)
492496
(if (hugo-extensions?)
493497
(let ((numbered (if numbered? '((numbered . "numbered")) '()))
494498
(args (cdr x)))
495-
(md-hugo-shortcode
499+
(md-hugo-shortcode*
496500
(append `(sidenote (halign . ,(md-marginal-style (first args)))
497501
(valign . ,(md-marginal-style (second args))))
498502
numbered)
@@ -574,71 +578,71 @@
574578

575579
(define serialize-hash (make-ahash-table))
576580
(map (lambda (l) (apply (cut ahash-set! serialize-hash <> <>) l))
577-
(list (list 'identity skip)
578-
(list 'markdown md-markdown)
579-
(list 'localize md-translate)
580-
(list 'labels md-labels)
581-
(list 'strong md-style)
582-
(list 'em md-style)
583-
(list 'tt md-style)
584-
(list 'strike md-style)
585-
(list 'underline md-style)
586-
(list 'block md-block)
587-
(list 'quotation md-quotation)
588-
(list 'document md-document)
589-
(list 'std-env (md-make-environment 'em))
590-
(list 'std-env* (md-make-environment* 'em))
591-
(list 'plain-env (md-make-environment 'identity))
592-
(list 'plain-env* (md-make-environment* 'identity))
593-
(list 'dueto md-dueto)
594-
(list 'math md-math)
595-
(list 'equation md-numbered-equation)
596-
(list 'equation* md-equation)
597-
(list 'eqnarray md-numbered-equation)
598-
(list 'eqnarray* md-equation)
599-
(list 'concat md-concat)
600-
(list 'item md-item)
601-
(list 'itemize md-list)
602-
(list 'enumerate md-list)
603-
(list 'h1 (md-header 1))
604-
(list 'h2 (md-header 2))
605-
(list 'h3 (md-header 3))
606-
(list 'para md-para)
607-
(list 'doc-date md-doc-date)
608-
(list 'doc-title md-doc-title)
609-
(list 'doc-subtitle md-doc-subtitle)
610-
(list 'doc-author md-doc-author)
611-
(list 'abstract md-abstract)
612-
(list 'paper-author-name paper-author-add) ; Paperwhy extension
613-
(list 'cite md-cite)
614-
(list 'cite-detail md-cite-detail)
615-
(list 'eqref md-eqref)
616-
(list 'label md-label)
617-
(list 'reference md-reference)
618-
(list 'footnote md-footnote)
619-
(list 'todo md-todo)
620-
(list 'image md-image)
621-
(list 'html-class md-html-class)
622-
(list 'small-figure (md-figure 'tmfigure '(class . "small-figure")))
623-
(list 'big-figure
624-
(md-figure 'tmfigure
625-
'(marginal-caption . #t) '(class . "big-figure")))
626-
(list 'wide-figure (md-figure 'tmfigure '(class . "wide-figure")))
627-
(list 'marginal-figure (md-figure 'sidefigure))
628-
(list 'small-table (md-figure 'tmfigure))
629-
(list 'big-table (md-figure 'tmfigure ))
630-
(list 'tabular md-tabular)
631-
(list 'hlink md-hlink)
632-
(list 'tags md-hugo-tags) ; Hugo extension (DEPRECATED)
633-
(list 'hugo-short md-hugo-shortcode) ; Hugo extension
634-
(list 'hugo-front md-hugo-frontmatter) ; Hugo extension
635-
(list 'table-of-contents md-toc) ; Hugo extension
636-
(list 'bibliography md-bibliography) ; TfL extension
637-
(list 'marginal-note md-sidenote) ; TfL extension
638-
(list 'marginal-note* md-sidenote*) ; TfL extension
639-
(list 'explain-macro md-explain-macro)
640-
(list 'tmdoc-copyright md-tmdoc-copyright)
641-
))
581+
(list
582+
(list 'abstract md-abstract)
583+
(list 'bibliography md-bibliography) ; TfL extension
584+
(list 'big-figure
585+
(md-figure 'tmfigure '(marginal-caption . #t) '(class . "big-figure")))
586+
(list 'big-table (md-figure 'tmfigure ))
587+
(list 'block md-block)
588+
(list 'cite-detail md-cite-detail)
589+
(list 'cite md-cite)
590+
(list 'concat md-concat)
591+
(list 'doc-author md-doc-author)
592+
(list 'doc-date md-doc-date)
593+
(list 'doc-subtitle md-doc-subtitle)
594+
(list 'doc-title md-doc-title)
595+
(list 'document md-document)
596+
(list 'dueto md-dueto)
597+
(list 'em md-style)
598+
(list 'enumerate md-list)
599+
(list 'eqnarray* md-equation)
600+
(list 'eqnarray md-numbered-equation)
601+
(list 'eqref md-eqref)
602+
(list 'equation* md-equation)
603+
(list 'equation md-numbered-equation)
604+
(list 'explain-macro md-explain-macro)
605+
(list 'footnote md-footnote)
606+
(list 'h1 (md-header 1))
607+
(list 'h2 (md-header 2))
608+
(list 'h3 (md-header 3))
609+
(list 'hlink md-hlink)
610+
(list 'html-class md-html-class)
611+
(list 'hugo-front md-hugo-frontmatter) ; Hugo extension
612+
(list 'hugo-short md-hugo-shortcode) ; Hugo extension
613+
(list 'identity skip)
614+
(list 'image md-image)
615+
(list 'itemize md-list)
616+
(list 'item md-item)
617+
(list 'label md-label)
618+
(list 'labels md-labels)
619+
(list 'localize md-translate)
620+
(list 'marginal-figure (md-figure 'sidefigure))
621+
(list 'marginal-note md-sidenote) ; TfL extension
622+
(list 'marginal-note* md-sidenote*) ; TfL extension
623+
(list 'markdown md-markdown)
624+
(list 'math md-math)
625+
(list 'paper-author-name paper-author-add) ; Paperwhy extension
626+
(list 'para md-para)
627+
(list 'plain-env (md-make-environment 'identity))
628+
(list 'plain-env* (md-make-environment* 'identity))
629+
(list 'quotation md-quotation)
630+
(list 'reference md-reference)
631+
(list 'small-figure (md-figure 'tmfigure '(class . "small-figure")))
632+
(list 'small-table (md-figure 'tmfigure))
633+
(list 'std-env (md-make-environment 'em))
634+
(list 'std-env* (md-make-environment* 'em))
635+
(list 'strike md-style)
636+
(list 'strong md-style)
637+
(list 'table-of-contents md-toc) ; Hugo extension
638+
(list 'tabular md-tabular)
639+
(list 'tags md-hugo-tags) ; Hugo extension (DEPRECATED)
640+
(list 'tmdoc-copyright md-tmdoc-copyright)
641+
(list 'todo md-todo)
642+
(list 'tt md-style)
643+
(list 'underline md-style)
644+
(list 'wide-figure (md-figure 'tmfigure '(class . "wide-figure")))
645+
))
642646

643647
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
644648
;; Public interface

0 commit comments

Comments
 (0)