commit d010fcc91719e391bde6e96f0ec7564ff92f0b35 Author: Bastien Dumont Date: Wed Oct 13 09:03:25 2021 +0200 Initialisation (avant implémentation des énumérations) diff --git a/README.md b/README.md new file mode 100644 index 0000000..b4c2037 --- /dev/null +++ b/README.md @@ -0,0 +1,152 @@ +# text-crossrefs: getting references to page and note numbers in Pandoc + +This filters aims at extending Pandoc's cross-referencing +capacities by enabling automatic references to any piece of text +by either its page or, whenever it applies, its note number. It +currently supports the following target formats: + + * context + * docx + * latex + * odt + * opendocument + +It doesn't permit to refer to references in other files: if you want to do this, use text-extrefs. + +N.-B.: When opening for the first time a DOCX or ODT/Opendocument file produced by Pandoc with text-crossrefs, you probably will have to refresh the fields in order to get the correct values. In LibreOffice, press `F9`; in Word, a dialog box should appear when the file opens. + +## Usage + +### Basics + +Mark the span of text you want to refer to later with an +identifier composed of alphanumeric characters, periods, colons, underscores and hyphens: + +``` markdown +Émile Gaboriau published [_L'Affaire Lerouge_ in +1866]{#publication}.[^1] + +[^1]: It is a very [fine piece of literature]{#my-evaluation}. + +[It was very popular.]{#reception} +``` + +You can refer to it using another span with class `ref` containing +the target's identifier. If the targetted span is part of a +footnote, you can refer to it either by page or by note number according to +the value of the `type` attribute (defaults to `page`). For instance, this: + +``` markdown +See [publication]{.ref} for the publication date. I gave my +opinion in [my-evaluation]{.ref type=note}, [my-evaluation]{.ref}. +``` + +will render in LaTeX output: + +``` tex +See p. \pageref{publication} for the publication date. I expressed +my thoughts about it in \ref{my-evaluation}, +p. \pageref{my-evaluation}. +``` + +If you want to give a reference by note and page number like in the example above, you can also use the following shorthand: + +```md +[my-evaluation]{.ref type=pagenote} +``` + +You can refer to headers as well using either explicit or automatically generated identifiers (see Pandoc user’s guide). + +### Page ranges + +You can refer to a page range like this: + +``` markdown +If you want to know more about _L'Affaire Lerouge_, see [publication>reception]{.ref}. +``` + +The separator (here `>`) can be set to any string composed of characters other than alphanumeric, period, colon, underscore, hyphen and space. + +In LaTeX and ConTeXt output, the page range will be printed as a simple page reference if the page numbers are identical. You can provide your own definition of the macro `\tcrfpagerangeref{}{}` in the preamble. In DOCX and ODT/Opendocument output, the same result can be achieved in a word processor by the means of automatic search and replace with regular expressions. + +## Enumerations + +Rather + +## Customization + +The following metadata fields can be set as strings: + + * `tcrf-page-prefix`: + * “page” prefix; + * defaults to `p. `. + * `tcrf-pages-prefix`: + * “pages” prefix; + * defaults to `p. `. + * `tcrf-note-prefix`: + * “note” prefix; + * defaults to `n. `. + * `tcrf-pagenote-separator`: + * the separator between the references when `type` is set to `pagenote`; + * defaults to `, `. + * `tcrf-pagenote-at-end`: + * the string printed at the end of a pagenote reference; + * defaults to an empty string, can be used to achieve something like *n. 3 (p. 5)*. + * `tcrf-pagenote-order`: + * the order in which the references to note and page are printed; + * defaults to `pagefirst`, can be set to `notefirst`. + * `tcrf-references-range-separator`: + * the string used to separate two references in a reference span; can be composed of any character not authorized in an identifier other than space or tab; + * defaults to `>`. + * `tcrf-range-separator`: + * the string inserted between to page numbers in a range; + * defaults to `-`. + * `tcrf-references-enum-separator`: + * the string used to separate the elements of an enumeration in a reference span; can be composed of any character not authorized in an identifier other than space or tab; + * defaults to `;`. + * `tcrf-enum-separator`: + * the string inserted between two elements (but the two last ones) in an enumeration; + * defaults to a comma followed by a space. + * `tcrf-before-last-in-enum`: + * the string inserted between the two last elements in an enumeration; + * defaults to `and` surrounded with spaces. + * `tcrf-only-explicit-labels`: + * set it to `true` if you want that _tcrf_ handle only spans with class `label`; + * defaults to `false`. + * `tcrf-default-info-type`: + * default value for the `type` attribute (`note`, `page` or `pagenote`); + * defaults to `page`. + * `tcrf-filelabel-ref-separator`: + * only useful in conjunction with the text-exrefs filter; + * separator between external files' labels and references; + * defaults to `::`. + +## Compatibility with other filters + +Text-crossrefs must be run after all other filters that can create, delete or move +footnotes, like citeproc. + +In order to give and identifier to a note produced by a citation inside square brackets, the span should not include the citation key, the locator or the `;` +delimiter. If it is placed immediatly after the locator, this should be surrounded by curly brackets. So this should work: + + ``` markdown + [@Jones1973, p. 5-70; @Doe2004[]{#jones-doe}] + + [@Jones1973, p. 5-70; [it was elaborated upon]{#further-elaboration} by @Doe2004] + + [@Jones1973, {p. 5-70}[]{#ref-to-jones}; @Doe2004] + ``` + +not that: + + ``` markdown + [[@Jones1973, p. 5-70]{#ref-to-jones}; @Doe2004] + + [[@Jones1973, p. 5-70; @Doe2004]{#jones-doe}] + + [@Jones1973, p. 5-70[]{#ref-to-jones}; @Doe2004] + ``` + +You can set classes and attributes to your spans other than those defined by text-crossrefs (for instance `[some text]{#to-be-referred-to .highlighted color=red}` or `[reference]{.ref color=red}`). No span is removed. + +Text-crossrefs is fully compatible with text-extrefs. Whenever possible, when a metadata is not set for text-extrefs, its value is taken from its text-crossrefs equivalent, so that you don't need to duplicate similar variables. diff --git a/sample.md b/sample.md new file mode 100644 index 0000000..13c7f35 --- /dev/null +++ b/sample.md @@ -0,0 +1,27 @@ +--- +tcrf-pagenote-separator: '\ (' +tcrf-pagenote-at-end: ')' +--- + +Émile Gaboriau published [_L'Affaire Lerouge_ in +1866]{#publication}.[^1] + +[^1]: It is a very [fine piece of literature]{#my-evaluation}. + +[It was very popular.]{#reception} + +See [publication]{.ref} for the publication date. I expressed +my thoughts about it in [my-evaluation]{.ref type=pagenote}. + +If you want to know more about _L'Affaire Lerouge_, see [publication>reception]{.ref}. + +Here are some precisions.[^2] + +[^2]: [Whatever format]{#format} you choose, you can [refer to a note]{#refer-to-note} by the identifier of [any of its spans. You can even [nest spans]{#nested-spans}!]{#which-identifier} + +I want to refer to a note: + + * How can I refer to a note by its number? → See [refer-to-note]{.ref}. + * What formats are supported? → See [format]{.ref}. + * What if the note contains multiple spans with identifiers? → See [which-identifier]{.ref}. + * What happens if a span in contained in a span? → See [nested-spans]{.ref}. diff --git a/sampledocs/docx/[Content_Types].xml b/sampledocs/docx/[Content_Types].xml new file mode 100644 index 0000000..5f21f33 --- /dev/null +++ b/sampledocs/docx/[Content_Types].xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/sampledocs/docx/_rels/.rels b/sampledocs/docx/_rels/.rels new file mode 100644 index 0000000..fdd8c4f --- /dev/null +++ b/sampledocs/docx/_rels/.rels @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/sampledocs/docx/customXml/_rels/item1.xml.rels b/sampledocs/docx/customXml/_rels/item1.xml.rels new file mode 100644 index 0000000..a9c831d --- /dev/null +++ b/sampledocs/docx/customXml/_rels/item1.xml.rels @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/sampledocs/docx/customXml/item1.xml b/sampledocs/docx/customXml/item1.xml new file mode 100644 index 0000000..766e845 --- /dev/null +++ b/sampledocs/docx/customXml/item1.xml @@ -0,0 +1 @@ + diff --git a/sampledocs/docx/customXml/itemProps1.xml b/sampledocs/docx/customXml/itemProps1.xml new file mode 100644 index 0000000..ebcaae9 --- /dev/null +++ b/sampledocs/docx/customXml/itemProps1.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/sampledocs/docx/docProps/app.xml b/sampledocs/docx/docProps/app.xml new file mode 100644 index 0000000..c0832c6 --- /dev/null +++ b/sampledocs/docx/docProps/app.xml @@ -0,0 +1,2 @@ + +31847Microsoft Office Word011falsefalse54falsefalse14.0000 \ No newline at end of file diff --git a/sampledocs/docx/docProps/core.xml b/sampledocs/docx/docProps/core.xml new file mode 100644 index 0000000..5cf7d66 --- /dev/null +++ b/sampledocs/docx/docProps/core.xml @@ -0,0 +1,2 @@ + +Bastien DUMONTBastien DUMONT22021-05-22T09:07:00Z2021-05-22T09:17:00Z \ No newline at end of file diff --git a/sampledocs/docx/testref.docx b/sampledocs/docx/testref.docx new file mode 100755 index 0000000..93e23f8 Binary files /dev/null and b/sampledocs/docx/testref.docx differ diff --git a/sampledocs/docx/word/_rels/document.xml.rels b/sampledocs/docx/word/_rels/document.xml.rels new file mode 100644 index 0000000..ebee045 --- /dev/null +++ b/sampledocs/docx/word/_rels/document.xml.rels @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/sampledocs/docx/word/document.xml b/sampledocs/docx/word/document.xml new file mode 100644 index 0000000..6b6295c --- /dev/null +++ b/sampledocs/docx/word/document.xml @@ -0,0 +1,2 @@ + +Référence à la note : NOTEREF _Ref72574139 \h 1 \ No newline at end of file diff --git a/sampledocs/docx/word/endnotes.xml b/sampledocs/docx/word/endnotes.xml new file mode 100644 index 0000000..f95e6f1 --- /dev/null +++ b/sampledocs/docx/word/endnotes.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/sampledocs/docx/word/fontTable.xml b/sampledocs/docx/word/fontTable.xml new file mode 100644 index 0000000..e187e55 --- /dev/null +++ b/sampledocs/docx/word/fontTable.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/sampledocs/docx/word/footnotes.xml b/sampledocs/docx/word/footnotes.xml new file mode 100644 index 0000000..dbe8778 --- /dev/null +++ b/sampledocs/docx/word/footnotes.xml @@ -0,0 +1,2 @@ + + La note ici \ No newline at end of file diff --git a/sampledocs/docx/word/settings.xml b/sampledocs/docx/word/settings.xml new file mode 100644 index 0000000..425f092 --- /dev/null +++ b/sampledocs/docx/word/settings.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/sampledocs/docx/word/styles.xml b/sampledocs/docx/word/styles.xml new file mode 100644 index 0000000..4c27df6 --- /dev/null +++ b/sampledocs/docx/word/styles.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/sampledocs/docx/word/stylesWithEffects.xml b/sampledocs/docx/word/stylesWithEffects.xml new file mode 100644 index 0000000..25cd1cb --- /dev/null +++ b/sampledocs/docx/word/stylesWithEffects.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/sampledocs/docx/word/theme/theme1.xml b/sampledocs/docx/word/theme/theme1.xml new file mode 100644 index 0000000..f292589 --- /dev/null +++ b/sampledocs/docx/word/theme/theme1.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/sampledocs/docx/word/webSettings.xml b/sampledocs/docx/word/webSettings.xml new file mode 100644 index 0000000..88ba7f2 --- /dev/null +++ b/sampledocs/docx/word/webSettings.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/sampledocs/docx/~$estref.docx b/sampledocs/docx/~$estref.docx new file mode 100644 index 0000000..3d71b40 Binary files /dev/null and b/sampledocs/docx/~$estref.docx differ diff --git a/sampledocs/filter-docx/[Content_Types].xml b/sampledocs/filter-docx/[Content_Types].xml new file mode 100644 index 0000000..f8e3f00 --- /dev/null +++ b/sampledocs/filter-docx/[Content_Types].xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/sampledocs/filter-docx/_rels/.rels b/sampledocs/filter-docx/_rels/.rels new file mode 100644 index 0000000..ae7b3ed --- /dev/null +++ b/sampledocs/filter-docx/_rels/.rels @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/sampledocs/filter-docx/docProps/app.xml b/sampledocs/filter-docx/docProps/app.xml new file mode 100644 index 0000000..1764f14 --- /dev/null +++ b/sampledocs/filter-docx/docProps/app.xml @@ -0,0 +1,18 @@ + + + 83 + false + false + 12 + 12.0000 + false + Microsoft Word 12.0.0 + 583 + + 0 + 6 + false + 475 + 8 + 1 + \ No newline at end of file diff --git a/sampledocs/filter-docx/docProps/core.xml b/sampledocs/filter-docx/docProps/core.xml new file mode 100644 index 0000000..6336e34 --- /dev/null +++ b/sampledocs/filter-docx/docProps/core.xml @@ -0,0 +1 @@ +2021-05-23T17:28:34Z2021-05-23T17:28:34Z \ No newline at end of file diff --git a/sampledocs/filter-docx/docProps/custom.xml b/sampledocs/filter-docx/docProps/custom.xml new file mode 100644 index 0000000..bd63c79 --- /dev/null +++ b/sampledocs/filter-docx/docProps/custom.xml @@ -0,0 +1 @@ +) ( \ No newline at end of file diff --git a/sampledocs/filter-docx/test.docx b/sampledocs/filter-docx/test.docx new file mode 100644 index 0000000..93b7cc5 Binary files /dev/null and b/sampledocs/filter-docx/test.docx differ diff --git a/sampledocs/filter-docx/word/_rels/document.xml.rels b/sampledocs/filter-docx/word/_rels/document.xml.rels new file mode 100644 index 0000000..b5a18af --- /dev/null +++ b/sampledocs/filter-docx/word/_rels/document.xml.rels @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/sampledocs/filter-docx/word/_rels/footnotes.xml.rels b/sampledocs/filter-docx/word/_rels/footnotes.xml.rels new file mode 100644 index 0000000..bee2b8c --- /dev/null +++ b/sampledocs/filter-docx/word/_rels/footnotes.xml.rels @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/sampledocs/filter-docx/word/comments.xml b/sampledocs/filter-docx/word/comments.xml new file mode 100644 index 0000000..229ad01 --- /dev/null +++ b/sampledocs/filter-docx/word/comments.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/sampledocs/filter-docx/word/document.xml b/sampledocs/filter-docx/word/document.xml new file mode 100644 index 0000000..24a8f34 --- /dev/null +++ b/sampledocs/filter-docx/word/document.xml @@ -0,0 +1 @@ +Émile Gaboriau published L’Affaire Lerouge in 1866.It was very popular.See p.  PAGEREF publication_pageNb \h 000 for the publication date. I expressed my thoughts about it p.  PAGEREF my-evaluation_pageNb \h 000 (n.  NOTEREF my-evaluation_noteNb \h 000). \ No newline at end of file diff --git a/sampledocs/filter-docx/word/fontTable.xml b/sampledocs/filter-docx/word/fontTable.xml new file mode 100644 index 0000000..fce61de --- /dev/null +++ b/sampledocs/filter-docx/word/fontTable.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sampledocs/filter-docx/word/footnotes.xml b/sampledocs/filter-docx/word/footnotes.xml new file mode 100644 index 0000000..b692070 --- /dev/null +++ b/sampledocs/filter-docx/word/footnotes.xml @@ -0,0 +1,6 @@ + + + + + + It is a very fine piece of literature. \ No newline at end of file diff --git a/sampledocs/filter-docx/word/numbering.xml b/sampledocs/filter-docx/word/numbering.xml new file mode 100644 index 0000000..06fb610 --- /dev/null +++ b/sampledocs/filter-docx/word/numbering.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/sampledocs/filter-docx/word/settings.xml b/sampledocs/filter-docx/word/settings.xml new file mode 100644 index 0000000..2428379 --- /dev/null +++ b/sampledocs/filter-docx/word/settings.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sampledocs/filter-docx/word/styles.xml b/sampledocs/filter-docx/word/styles.xml new file mode 100644 index 0000000..723bc8d --- /dev/null +++ b/sampledocs/filter-docx/word/styles.xml @@ -0,0 +1,467 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sampledocs/filter-docx/word/theme/theme1.xml b/sampledocs/filter-docx/word/theme/theme1.xml new file mode 100644 index 0000000..a6f7240 --- /dev/null +++ b/sampledocs/filter-docx/word/theme/theme1.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/sampledocs/filter-docx/word/webSettings.xml b/sampledocs/filter-docx/word/webSettings.xml new file mode 100644 index 0000000..570ca8e --- /dev/null +++ b/sampledocs/filter-docx/word/webSettings.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/sampledocs/odt/META-INF/manifest.xml b/sampledocs/odt/META-INF/manifest.xml new file mode 100644 index 0000000..6d7e2e5 --- /dev/null +++ b/sampledocs/odt/META-INF/manifest.xml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/sampledocs/odt/Thumbnails/thumbnail.png b/sampledocs/odt/Thumbnails/thumbnail.png new file mode 100644 index 0000000..7754e74 Binary files /dev/null and b/sampledocs/odt/Thumbnails/thumbnail.png differ diff --git a/sampledocs/odt/content.xml b/sampledocs/odt/content.xml new file mode 100644 index 0000000..1f78043 --- /dev/null +++ b/sampledocs/odt/content.xml @@ -0,0 +1,2 @@ + +1La note iciRéférence à la note : 300p. 300Le marque-page est p. 300. diff --git a/sampledocs/odt/manifest.rdf b/sampledocs/odt/manifest.rdf new file mode 100644 index 0000000..927e206 --- /dev/null +++ b/sampledocs/odt/manifest.rdf @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/sampledocs/odt/meta.xml b/sampledocs/odt/meta.xml new file mode 100644 index 0000000..38ec226 --- /dev/null +++ b/sampledocs/odt/meta.xml @@ -0,0 +1,2 @@ + +Bastien Dumont2021-05-22T11:38:49.9363886482021-05-22T23:19:47.946633474Bastien DumontPT3M32S2LibreOffice/7.1.3.2$Linux_X86_64 LibreOffice_project/10$Build-2 \ No newline at end of file diff --git a/sampledocs/odt/mimetype b/sampledocs/odt/mimetype new file mode 100644 index 0000000..2e95b81 --- /dev/null +++ b/sampledocs/odt/mimetype @@ -0,0 +1 @@ +application/vnd.oasis.opendocument.text \ No newline at end of file diff --git a/sampledocs/odt/settings.xml b/sampledocs/odt/settings.xml new file mode 100644 index 0000000..7e29687 --- /dev/null +++ b/sampledocs/odt/settings.xml @@ -0,0 +1,2 @@ + +00764511996truefalseview2701129850076431199401false180falsefalsefalsefalsefalsetruetruetruetruetruefalse0falsefalsefalsetruefalsefalsetruefalsefalsefalsetruetruetruefalsefalsefalsefalsefalsefalsefalsetruefalsefalsetruefalsefalsefalsetrue01truefalsehigh-resolutiontruefalsefalsetruefalsetruetruefalsetruetrue455576truefalsetrue0falsefalsefalsetruefalsetruefalsefalsefalsefalsetruefalsefalsefalsetruefalsefalsefalsefalsefalsefalsefalsefalsefalse390281falsefalsefalsefalsefalsetruefalsetruetrue \ No newline at end of file diff --git a/sampledocs/odt/styles.xml b/sampledocs/odt/styles.xml new file mode 100644 index 0000000..88f85a9 --- /dev/null +++ b/sampledocs/odt/styles.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/sampledocs/odt/testref.odt b/sampledocs/odt/testref.odt new file mode 100644 index 0000000..b10362b Binary files /dev/null and b/sampledocs/odt/testref.odt differ diff --git a/sampledocs/pandoc-docx/[Content_Types].xml b/sampledocs/pandoc-docx/[Content_Types].xml new file mode 100644 index 0000000..f8e3f00 --- /dev/null +++ b/sampledocs/pandoc-docx/[Content_Types].xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/sampledocs/pandoc-docx/_rels/.rels b/sampledocs/pandoc-docx/_rels/.rels new file mode 100644 index 0000000..ae7b3ed --- /dev/null +++ b/sampledocs/pandoc-docx/_rels/.rels @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/sampledocs/pandoc-docx/docProps/app.xml b/sampledocs/pandoc-docx/docProps/app.xml new file mode 100644 index 0000000..1764f14 --- /dev/null +++ b/sampledocs/pandoc-docx/docProps/app.xml @@ -0,0 +1,18 @@ + + + 83 + false + false + 12 + 12.0000 + false + Microsoft Word 12.0.0 + 583 + + 0 + 6 + false + 475 + 8 + 1 + \ No newline at end of file diff --git a/sampledocs/pandoc-docx/docProps/core.xml b/sampledocs/pandoc-docx/docProps/core.xml new file mode 100644 index 0000000..1c8cf8d --- /dev/null +++ b/sampledocs/pandoc-docx/docProps/core.xml @@ -0,0 +1 @@ +2021-05-22T21:17:30Z2021-05-22T21:17:30Z \ No newline at end of file diff --git a/sampledocs/pandoc-docx/docProps/custom.xml b/sampledocs/pandoc-docx/docProps/custom.xml new file mode 100644 index 0000000..3d9de2d --- /dev/null +++ b/sampledocs/pandoc-docx/docProps/custom.xml @@ -0,0 +1 @@ +/home/bdumont/Documents/Doctorat/Redaction/Metadonnees/FEUILLE-STYLE_These.csl \ No newline at end of file diff --git a/sampledocs/pandoc-docx/test.docx b/sampledocs/pandoc-docx/test.docx new file mode 100644 index 0000000..4677c91 Binary files /dev/null and b/sampledocs/pandoc-docx/test.docx differ diff --git a/sampledocs/pandoc-docx/word/_rels/document.xml.rels b/sampledocs/pandoc-docx/word/_rels/document.xml.rels new file mode 100644 index 0000000..b5a18af --- /dev/null +++ b/sampledocs/pandoc-docx/word/_rels/document.xml.rels @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/sampledocs/pandoc-docx/word/_rels/footnotes.xml.rels b/sampledocs/pandoc-docx/word/_rels/footnotes.xml.rels new file mode 100644 index 0000000..bee2b8c --- /dev/null +++ b/sampledocs/pandoc-docx/word/_rels/footnotes.xml.rels @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/sampledocs/pandoc-docx/word/comments.xml b/sampledocs/pandoc-docx/word/comments.xml new file mode 100644 index 0000000..229ad01 --- /dev/null +++ b/sampledocs/pandoc-docx/word/comments.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/sampledocs/pandoc-docx/word/document.xml b/sampledocs/pandoc-docx/word/document.xml new file mode 100644 index 0000000..0e2b5f8 --- /dev/null +++ b/sampledocs/pandoc-docx/word/document.xml @@ -0,0 +1 @@ +Du texte.Du texte.Du texte.Du texte.Du texte.Du texte.Du texte.Du texte.Du texte.Du texte.Du texte.Du texte.Du texte.Du texte.Du texte.Du texte.Du texte.Du texte.Du texte.Du texte. \ No newline at end of file diff --git a/sampledocs/pandoc-docx/word/fontTable.xml b/sampledocs/pandoc-docx/word/fontTable.xml new file mode 100644 index 0000000..fce61de --- /dev/null +++ b/sampledocs/pandoc-docx/word/fontTable.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sampledocs/pandoc-docx/word/footnotes.xml b/sampledocs/pandoc-docx/word/footnotes.xml new file mode 100644 index 0000000..ba1176a --- /dev/null +++ b/sampledocs/pandoc-docx/word/footnotes.xml @@ -0,0 +1,101 @@ + + + + + + La note 1. + + + + + La note 2. + + + + + citation? + + + + + La note 4. + + + + + La note 4. + + + + + La note 4. + + + + + La note 4. + + + + + La note 4. + + + + + La note 4. + + + + + La note 4. + + + + + La note 4. + + + + + La note 4. + + + + + La note 4. + + + + + La note 4. + + + + + La note 4. + + + + + La note 4. + + + + + La note 4. + + + + + La note 4. + + + + + La note 4. + + + + + La note 4. \ No newline at end of file diff --git a/sampledocs/pandoc-docx/word/numbering.xml b/sampledocs/pandoc-docx/word/numbering.xml new file mode 100644 index 0000000..06fb610 --- /dev/null +++ b/sampledocs/pandoc-docx/word/numbering.xml @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/sampledocs/pandoc-docx/word/settings.xml b/sampledocs/pandoc-docx/word/settings.xml new file mode 100644 index 0000000..2428379 --- /dev/null +++ b/sampledocs/pandoc-docx/word/settings.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sampledocs/pandoc-docx/word/styles.xml b/sampledocs/pandoc-docx/word/styles.xml new file mode 100644 index 0000000..723bc8d --- /dev/null +++ b/sampledocs/pandoc-docx/word/styles.xml @@ -0,0 +1,467 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sampledocs/pandoc-docx/word/theme/theme1.xml b/sampledocs/pandoc-docx/word/theme/theme1.xml new file mode 100644 index 0000000..a6f7240 --- /dev/null +++ b/sampledocs/pandoc-docx/word/theme/theme1.xml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/sampledocs/pandoc-docx/word/webSettings.xml b/sampledocs/pandoc-docx/word/webSettings.xml new file mode 100644 index 0000000..570ca8e --- /dev/null +++ b/sampledocs/pandoc-docx/word/webSettings.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/sampledocs/testref.odt b/sampledocs/testref.odt new file mode 100644 index 0000000..3cc51b6 Binary files /dev/null and b/sampledocs/testref.odt differ diff --git a/test.md b/test.md new file mode 100644 index 0000000..8947f69 --- /dev/null +++ b/test.md @@ -0,0 +1,16 @@ +--- +tcrf-pagenote-separator: '\ (' +tcrf-pagenote-at-end: ')' +--- + +Émile Gaboriau published [_L'Affaire Lerouge_ in +1866]{#publication}.[^1] + +[^1]: It is a very [fine piece of literature]{#my-evaluation}. + +[It was very popular.]{#reception} + +See [publication]{.ref} for the publication date. I expressed +my thoughts about it [my-evaluation]{.ref type=pagenote}. + +Page range: [publication>reception]{.ref} diff --git a/text-crossrefs.lua b/text-crossrefs.lua new file mode 100644 index 0000000..f4a62f3 --- /dev/null +++ b/text-crossrefs.lua @@ -0,0 +1,458 @@ +-- TODO : permettre la citation de références multiples avec un seul préfixe +-- [ref-one, ref-two>ref-four, ref-three]{.ref} → pp. 1, 3-6 et 12 +-- Compléter README et test une fois que ce sera fait. + +-- Begin of initialization + +local IDENTIFIER_PATTERN = '[%w_.:-]+' +local RAW_ATTRIBUTE +local IS_LABEL_SET_BY_PANDOC +local LABEL_TEMPLATE +local NOTELABEL_TEMPLATE + +local function define_raw_attribute() + if FORMAT == 'native' then + RAW_ATTRIBUTE = pandoc.system.environment().TESTED_FORMAT + elseif FORMAT == 'docx' then + RAW_ATTRIBUTE = 'openxml' + elseif FORMAT == 'odt' or FORMAT == 'opendocument' then + RAW_ATTRIBUTE = 'opendocument' + elseif FORMAT == 'context' or FORMAT == 'latex' then + RAW_ATTRIBUTE = FORMAT + else + error(FORMAT .. + ' output not supported by text-crossrefs.lua.') + end +end + +local function define_label_template() + if RAW_ATTRIBUTE == 'opendocument' or RAW_ATTRIBUTE == 'openxml' then + IS_LABEL_SET_BY_PANDOC = true + elseif RAW_ATTRIBUTE == 'context' then + if PANDOC_VERSION < pandoc.types.Version('2.14') then + LABEL_TEMPLATE = '\\pagereference[{{label}}]' + else + IS_LABEL_SET_BY_PANDOC = true + end + elseif RAW_ATTRIBUTE == 'latex' then + LABEL_TEMPLATE = '\\label{{{label}}}' + end +end + +define_raw_attribute() +define_label_template() + +-- End of initialization + +-- Configuration + +local config = { + page_prefix = 'p. ', + pages_prefix = 'p. ', + note_prefix = 'n. ', + pagenote_order = 'pagefirst', + pagenote_separator = ', ', + pagenote_at_end = '', + references_range_separator = '>', + range_separator = '-', + only_explicit_labels = 'false', + default_info_type = 'page', + filelabel_ref_separator = '::' +} + +local function format_config_to_openxml() + to_format = { 'page_prefix', + 'pages_prefix', + 'note_prefix', + 'pagenote_separator', + 'pagenote_at_end', + 'range_separator' } + for i = 1, #to_format do + config[to_format[i]] = '' .. + config[to_format[i]] .. '' + end +end + +local function set_configuration_item_from_metadata(item, metamap) + metakey = 'tcrf-' .. string.gsub(item, '_', '-') + if metamap[metakey] then + -- The metadata values are Str in MetaInlines. + config[item] = metamap[metakey][1].c + end +end + +local function configure(metadata) + for item, _ in pairs(config) do + set_configuration_item_from_metadata(item, metadata) + end + if RAW_ATTRIBUTE == 'openxml' then + format_config_to_openxml() + end +end + +-- End of configuration + +-- Extensions for the output document's format + +local function define_tex_macros(document) + if RAW_ATTRIBUTE == 'context' then + local footnote_redefinition = '\\let\\oldfootnote\\footnote\n' .. + '\\define[2]\\footnote{\\oldfootnote[#2]{#1}%\n' .. + '\\expandafter\\edef\\csname #2pagenumber\\endcsname{\\userpage}}\n' + local predefined_strings = + '\\define\\tcrfpage{' .. config.page_prefix .. '}\n' .. + '\\define\\tcrfpages{' .. config.pages_prefix .. '}\n' .. + '\\define\\tcrfrangesep{' .. config.range_separator .. '}\n' + local range_ref = '\\ifdefined\\tcrfpagerangeref\\else\n' .. + '\\define[2]\\tcrfpagerangeref{' .. + '\\if' .. + '\\csname #1pagenumber\\endcsname' .. + '\\csname #2pagenumber\\endcsname\n' .. + '\\tcrfpage\\at[#1]\n' .. + '\\else\n' .. + '\\tcrfpages\\at[#1]\\tcrfrangesep\\at[#2]\\fi}\n' .. + '\\fi\n' + local macros_block = pandoc.RawBlock('context', + footnote_redefinition .. + predefined_strings .. + range_ref) + table.insert(document.blocks, 1, macros_block) + elseif RAW_ATTRIBUTE == 'latex' then + local predefined_strings = + '\\newcommand*{\\tcrfpage}{' .. config.page_prefix .. '}\n' .. + '\\newcommand*{\\tcrfpages}{' .. config.pages_prefix .. '}\n' .. + '\\newcommand*{\\tcrfrangesep}{' .. config.range_separator .. '}\n' + local label_redefinition = '\\let\\oldlabel\\label\n' .. + '\\renewcommand*{\\label}[1]{\\oldlabel{#1}%\n' .. + '\\expandafter\\xdef\\csname #1pagenumber\\endcsname{\\thepage}}\n' + local range_ref = '\\ifdefined\\tcrfpagerangeref\\else\n' .. + '\\newcommand*{\\tcrfpagerangeref}[2]{%\n' .. + '\\if' .. + '\\csname #1pagenumber\\endcsname' .. + '\\csname #2pagenumber\\endcsname\n' .. + '\\tcrfpage\\pageref{#1}\n' .. + '\\else\n' .. + '\\tcrfpages\\pageref{#1}\\tcrfrangesep\\pageref{#2}\\fi}\n' .. + '\\fi\n' + local macros_block = pandoc.RawBlock('latex', + predefined_strings .. + label_redefinition .. + range_ref) + table.insert(document.blocks, 1, macros_block) + end + return document +end + +-- End of the extensions for the output document's format + +-- Identifiers + +local spans_to_note_labels = {} +local current_odt_note_index = 0 +local is_first_span_in_note = true +local current_note_label + +local function map_span_to_label(span) + if RAW_ATTRIBUTE == 'opendocument' then + spans_to_note_labels[span.identifier] = 'ftn' .. current_odt_note_index + elseif RAW_ATTRIBUTE == 'openxml' or RAW_ATTRIBUTE == 'context' then + if is_first_span_in_note then + current_note_label = span.identifier + is_first_span_in_note = false + end + spans_to_note_labels[span.identifier] = current_note_label + end +end + +local function map_spans_to_labels(container) + for i = 1, #container.content do + -- The tests must be separate in order to support spans inside spans. + if container.content[i].t == 'Span' + and container.content[i].identifier ~= '' + then + map_span_to_label(container.content[i]) + end + if container.content[i].content then + map_spans_to_labels(container.content[i]) + end + end +end + +local function map_spans_to_notelabels(note) + if RAW_ATTRIBUTE == 'context' + or RAW_ATTRIBUTE == 'opendocument' + or RAW_ATTRIBUTE == 'openxml' then + is_first_span_in_note = true + map_spans_to_labels(note) + current_odt_note_index = current_odt_note_index + 1 + end +end + +local function make_label(label) + if IS_LABEL_SET_BY_PANDOC then + return pandoc.Str('') + else + label_rawcode = string.gsub(LABEL_TEMPLATE, '{{label}}', label) + return pandoc.RawInline(RAW_ATTRIBUTE, label_rawcode) + end +end + +local function labelize_span(span) + if span.identifier ~= '' then + local label = span.identifier + local label_begin = make_label(label, 'begin') + return { label_begin, span } + end +end + +local function has_class(elem, class) + if elem.classes then + for i = 1, #elem.classes do + if elem.classes[i] == class then + return true + end + end + return false + else + error('function has_class used on an element of type ' .. + elem.t .. ' that cannot have classes.') + end +end + +local current_note_labels = {} + +local collect_note_labels = { + Span = function(span) + if span.identifier ~= '' and + (config.only_explicit_labels == 'false' or has_class(span, 'label')) + then + table.insert(current_note_labels, span.identifier) + end + end +} + +local function make_notelabel(pos) + local raw_code = '' + if pos == 'begin' then + if RAW_ATTRIBUTE == 'openxml' then + raw_code = string.gsub( + '', + '{{label}}', current_note_labels[#current_note_labels]) + end + elseif pos == 'end' then + if RAW_ATTRIBUTE == 'context' then + local label = current_note_labels[1] .. '_note' + raw_code = '{' .. label .. '}' + elseif RAW_ATTRIBUTE == 'openxml' then + raw_code = string.gsub('', + '{{label}}', current_note_labels[1]) + end + end + return pandoc.RawInline(RAW_ATTRIBUTE, raw_code) +end + +local function labelize_note(note) + local label_begin = make_notelabel('begin') + local label_end = make_notelabel('end') + return { label_begin, note, label_end } +end + +function set_notelabels(note) + current_note_labels = {} + pandoc.walk_inline(note, collect_note_labels) + if #current_note_labels > 0 then + return labelize_note(note) + end +end + +-- End of identifiers-related code + +-- References + +local function is_reference_valid(ref) + if string.find(ref, '^[' .. IDENTIFIER_PATTERN .. ']') then + error('text-crossrefs.lua: Invalid character in reference: ' .. ref .. + '\nIdentifier and reference names can only contain' .. + ' alphanumerical characters, periods, underscores and hyphens.\n') + else + return true + end +end + +local function is_ref_external(rawref) + if string.find(rawref, config.filelabel_ref_separator, 1, true) then + return true + else + return false + end +end + +local function is_ref_range(rawref) + if string.find(rawref, config.references_range_separator, 1, true) then + return true + else + return false + end +end + +function get_first_reference_end_index(range_separator_index) + if range_separator_index then + return range_separator_index - 1 + end +end + +local function get_first_reference(rawref) + local _, file_ref_separator_index = + string.find(rawref, config.filelabel_ref_separator, 1, true) + local range_separator_index, _ = + string.find(rawref, config.references_range_separator, 1, true) + local ref = string.sub(rawref, + (file_ref_separator_index or 0) + 1, + get_first_reference_end_index(range_separator_index)) + if is_reference_valid(ref) then return ref end +end + +local function get_second_reference(rawref) + local second_ref_begin_index + local _, file_ref_separator_index = + string.find(rawref, config.filelabel_ref_separator, 1, true) + if file_ref_separator_index then + _, file_ref_separator_index = + string.find(rawref, + config.filelabel_ref_separator, + config.file_ref_separator_index + 1, + true) + second_ref_begin_index = file_ref_separator_index + 1 + else + local _, range_separator_index, _ = + string.find(rawref, config.references_range_separator, 1, true) + second_ref_begin_index = range_separator_index + 1 + end + local ref = string.sub(rawref, second_ref_begin_index) + if is_reference_valid(ref) then return ref end +end + +local function analyze_reference_span(reference_span) + if #reference_span.content == 1 and reference_span.content[1].t == 'Str' then + raw_reference = reference_span.content[1].c + analyzed_reference = {} + analyzed_reference.is_external = is_ref_external(raw_reference) + analyzed_reference.is_range = is_ref_range(raw_reference) + if analyzed_reference.is_external then + analyzed_reference.filelabel = get_extfilelabel(raw_reference) + end + analyzed_reference.first = get_first_reference(raw_reference) + if analyzed_reference.is_range then + analyzed_reference.second = get_second_reference(raw_reference) + end + return analyzed_reference + else + error('The content of a span with class ref must be a plain string.') + end +end + +local function insert_page_target_in_xml(target) + if RAW_ATTRIBUTE == 'opendocument' then + return '000' + elseif RAW_ATTRIBUTE == 'openxml' then + return '' .. + ' PAGEREF ' .. + target .. ' \\h ' .. + '' .. + '000' .. + '' + end +end + +local function format_page_reference(target) + if RAW_ATTRIBUTE == 'context' then + return config.page_prefix .. '\\at[' .. target .. ']' + elseif RAW_ATTRIBUTE == 'latex' then + return config.page_prefix .. '\\pageref{' .. target .. '}' + elseif RAW_ATTRIBUTE == 'opendocument' then + return config.page_prefix .. insert_page_target_in_xml(target) + elseif RAW_ATTRIBUTE == 'openxml' then + return config.page_prefix .. insert_page_target_in_xml(target) + end +end + +local function format_pagerange_reference(first, second) + if RAW_ATTRIBUTE == 'context' or RAW_ATTRIBUTE == 'latex' then + return '\\tcrfpagerangeref{' .. first .. '}{' .. second .. '}' + elseif RAW_ATTRIBUTE == 'opendocument' or RAW_ATTRIBUTE == 'openxml' then + return config.pages_prefix .. insert_page_target_in_xml(first) .. + config.range_separator .. insert_page_target_in_xml(second) + end +end + +local function format_note_reference(target) + if RAW_ATTRIBUTE == 'context' then + return config.note_prefix .. '\\in[' .. spans_to_note_labels[target] .. '_note' .. ']' + elseif RAW_ATTRIBUTE == 'latex' then + return config.note_prefix .. '\\ref{' .. target .. '}' + elseif RAW_ATTRIBUTE == 'opendocument' then + return config.note_prefix .. '000' + elseif RAW_ATTRIBUTE == 'openxml' then + return config.note_prefix .. + '' .. + ' NOTEREF ' .. + target .. '_Note' .. ' \\h ' .. + '' .. + '000' .. + '' + end +end + +local function format_pagenote_reference(target) + if config.pagenote_order == 'pagefirst' then + return format_page_reference(target) .. config.pagenote_separator .. + format_note_reference(target) .. config.pagenote_at_end + elseif config.pagenote_order == 'notefirst' then + return format_note_reference(target) .. config.pagenote_separator .. + format_page_reference(target) .. config.pagenote_at_end + else + error('tcrf-pagenote-order must be set either to pagefirst or notefirst.') + end +end + +local function format_reference(target, info_type) + if info_type == 'page' and target.is_range then + return format_pagerange_reference(target.first, target.second) + elseif info_type == 'page' then + return format_page_reference(target.first) + elseif info_type == 'note' then + return format_note_reference(target.first) + elseif info_type == 'pagenote' then + return format_pagenote_reference(target.first) + else + error('Invalid value for attribute type in span with class ref: ' .. + info_type) + end +end + +local function make_reference(span) + if has_class(span, 'ref') then + local target = analyze_reference_span(span) + if not target.is_external then + local info_type = span.attributes.type or config.default_info_type + local formatted_reference = format_reference(target, info_type) + span.content[1] = pandoc.RawInline(RAW_ATTRIBUTE, formatted_reference) + return span + end + end +end + +-- End of references-related code + +return { + { Meta = configure }, + { Pandoc = define_tex_macros }, + { Note = set_notelabels }, + { Note = map_spans_to_notelabels }, + { Span = labelize_span }, + { Span = make_reference } +}