|
| 1 | +--- |
| 2 | +title: "Not-in-format - Keep document parts out of selected output |
| 3 | + formats" |
| 4 | +author: "Julien Dutant" |
| 5 | +--- |
| 6 | + |
| 7 | +Not-in-format |
| 8 | +======= |
| 9 | + |
| 10 | +Keeps parts of a document out of selected output formats. |
| 11 | + |
| 12 | +v1.0. Copyright: © 2021 Julien Dutant < [email protected]> |
| 13 | +License: MIT - see LICENSE file for details. |
| 14 | + |
| 15 | +Usage |
| 16 | +----- |
| 17 | + |
| 18 | +This Lua filter for Pandoc that keeps parts of a document out of selected outputs formats. |
| 19 | + |
| 20 | +*Use case*. Sometimes a bit of markdown will convert well through Pandoc |
| 21 | +to some formats not others. Say, you have a table that is reasonably |
| 22 | +well converted to html and docx, but you want more control on the |
| 23 | +LaTeX output. This filter allows you to: |
| 24 | + |
| 25 | +* Enter the desired LaTeX table output as a [fenced block with a raw |
| 26 | + attribute](https://pandoc.org/MANUAL.html#extension-raw_attribute). |
| 27 | +* Mark up the markdown table so that it is output only in formats other |
| 28 | + than LaTeX. |
| 29 | + |
| 30 | +*Usage*. Mark up the part you want to keep out of some output format(s) |
| 31 | +as a native Div with the attributes `not-in-format` and the names of the |
| 32 | +format(s) in question: |
| 33 | + |
| 34 | +```markdown |
| 35 | +::: {.not-in-format .latex .beamer} |
| 36 | + |
| 37 | +--------------------------- |
| 38 | +This table is not kept |
| 39 | +----------- ---------------- |
| 40 | +in formats latex, beamer |
| 41 | +---------------------------- |
| 42 | + |
| 43 | +::: |
| 44 | +``` |
| 45 | + |
| 46 | +Use format names for [Pandoc's list of output formats](https://pandoc.org/MANUAL.html#option--to), which you can print out by running ```pandoc --list-output-formats```. |
| 47 | + |
| 48 | +You would normally provide a raw equivalent for the part in question in |
| 49 | +the format(s) in question, using Pandoc's [fenced blocks with a raw |
| 50 | +attribute](https://pandoc.org/MANUAL.html#extension-raw_attribute): |
| 51 | + |
| 52 | +```markdown |
| 53 | +::: {.not-in-format .latex .beamer} |
| 54 | + |
| 55 | +--------------------------- |
| 56 | +This table is not kept |
| 57 | +----------- ---------------- |
| 58 | +in formats latex, beamer |
| 59 | +---------------------------- |
| 60 | + |
| 61 | +::: |
| 62 | + |
| 63 | +~~~{=latex} |
| 64 | + |
| 65 | +begin{tabular}{|c|c|} |
| 66 | +\toprule |
| 67 | +This table & is not kept \\ \addlinespace |
| 68 | +\midrule |
| 69 | +\endhead |
| 70 | +in formats & latex, beamer \\ \addlinespace |
| 71 | +\bottomrule |
| 72 | +\end{tabluar} |
| 73 | + |
| 74 | +~~~ |
| 75 | +``` |
| 76 | + |
| 77 | +A fenced block with a raw attribute can only have one attribute, so you |
| 78 | +need one for each format for which the markdown is left out. But Pandoc |
| 79 | +will output the raw block in equivalent formats: a `latex` block will |
| 80 | +be output in `latex` and `beamer`, a `html5` block in `html` and `epub3` |
| 81 | +and so on. See [Pandoc's manual](https://pandoc.org/MANUAL.html#extension-raw_attribute). |
| 82 | + |
| 83 | +Installation |
| 84 | +------------ |
| 85 | + |
| 86 | +Copy `not-in-format.lua` in your document folder or in your pandoc data |
| 87 | +dir path. |
| 88 | + |
| 89 | +Contributing |
| 90 | +------------ |
| 91 | + |
| 92 | +PRs welcome. |
0 commit comments