Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 deletions filter/divide-code-blocks.lua
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
-- draw horizontal rules above and below code blocks to separate them nicely

code_classes =
fontsize_classes =
{
["normal"] = {
["font"] = "\\small",
},
["small"] = {
["font"] = "\\scriptsize",
},
["tiny"] = {
["font"] = "\\tiny",
},
["normal"] = "\\small",
["small"] = "\\scriptsize",
["tiny"] = "\\tiny",
}

function CodeBlock(block)
local class_spec = code_classes["normal"]
local fontsize = fontsize_classes["normal"]
for _, class in ipairs(block.classes) do
local maybe_spec = code_classes[string.lower(class)]
if maybe_spec then
class_spec = maybe_spec
local maybe_fontsize = fontsize_classes[string.lower(class)]
if maybe_fontsize then
fontsize = maybe_fontsize
break
end
end
Expand All @@ -30,11 +24,10 @@ function CodeBlock(block)

block.text = block.text:gsub("\r", "") -- Remove carriage-returns.

font = class_spec["font"]
return {
pandoc.RawInline('latex', string.format([[
\BeginCodeBlock{%s}
]], font)),
]], fontsize)),
block,
pandoc.RawInline('latex', [[
\EndCodeBlock
Expand Down
21 changes: 20 additions & 1 deletion filter/tabularx.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
-- Use xltabular's xltabular environment instead of longtable to write LaTeX tables.
-- Run this filter after pandoc-crossref.

fontsize_classes =
{
["normal"] = "\\small",
["small"] = "\\scriptsize",
["tiny"] = "\\tiny",
}

function Length(element)
local n = 0
for key, value in pairs(element) do
Expand Down Expand Up @@ -234,6 +241,15 @@ end
-- which gives us the option to draw the full grid of the table.
function Table(tbl)
if FORMAT =='latex' then
local fontsize = fontsize_classes["normal"]
for _, class in ipairs(tbl.classes) do
local maybe_fontsize = fontsize_classes[string.lower(class)]
if maybe_fontsize then
fontsize = maybe_fontsize
break
end
end

tbl.colspecs = NormalizeColumns(tbl.colspecs)
local latex_code = ''

Expand Down Expand Up @@ -275,6 +291,9 @@ function Table(tbl)
latex_code = latex_code .. '\\addtocounter{table}{-1}\n'
end

-- Set the font size.
latex_code = latex_code .. '\\begingroup' .. fontsize

--
-- Begin the xltabular environment
--
Expand Down Expand Up @@ -370,7 +389,7 @@ function Table(tbl)
-- End the tabular environment
--

latex_code = latex_code .. '\\end{xltabular}\n'
latex_code = latex_code .. '\\end{xltabular}\\endgroup\n'

-- Return a raw LaTeX blob with our encoded table.
return pandoc.RawBlock('tex', latex_code)
Expand Down
50 changes: 50 additions & 0 deletions guide.tcg
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,56 @@ Each type of Markdown table provides different support for alignment. See the
[Pandoc table documentation](https://pandoc.org/chunkedhtml-demo/8.9-tables.html)
for more details.

#### Font size

The font size of tables can be customized via the `.small` or `.tiny` classes.

```md
Table: Font size demonstration (small) {#tbl:fontsize-demonstration .small}

+-------+-------+-----------------+
| Fruit | Color | Description |
+=======+=======+=================+
| Apple | Red | Useful for pie. |
+-------+-------+-----------------+
| Pear | Green | Useful for pie? |
+-------+-------+-----------------+

Here is how to customize the font size of a table that has no caption:

: {.tiny}

+--------+--------+---------------------+
| Fruit | Color | Description |
+========+========+=====================+
| Banana | Yellow | Useful for pie. |
+--------+--------+---------------------+
| Tomato | Red | Not useful for pie. |
+--------+--------+---------------------+
```

These tables render like so:

Table: Font size demonstration (small) {#tbl:fontsize-demonstration .small}

+-------+-------+-----------------+
| Fruit | Color | Description |
+=======+=======+=================+
| Apple | Red | Useful for pie. |
+-------+-------+-----------------+
| Pear | Green | Useful for pie? |
+-------+-------+-----------------+

: {.tiny}

+--------+--------+---------------------+
| Fruit | Color | Description |
+========+========+=====================+
| Banana | Yellow | Useful for pie. |
+--------+--------+---------------------+
| Tomato | Red | Not useful for pie. |
+--------+--------+---------------------+

## HTML Tables {#sec:html-tables}

A rowspan/colspan table like @tbl:fruits-grid can be implemented in HTML like
Expand Down