Skip to content

Commit

Permalink
Add options to Lua examples pgf-tikz#640 pgf-tikz#839
Browse files Browse the repository at this point in the history
  • Loading branch information
hmenke committed Jun 17, 2020
1 parent bd8c9c4 commit 6a0e08d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 15 deletions.
28 changes: 18 additions & 10 deletions tex/generic/pgf/graphdrawing/lua/pgf/gd/force/ControlElectric.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,24 @@ declare {
Two typical effects of increasing the |electric charge| are distortion
of symmetries and an upscaling of the drawings.
"]],
examples = {[["
\tikz \graph [spring electrical layout, horizontal=0 to 1]
{ 0 [electric charge=1] -- subgraph C_n [n=10] };
"]],[["
\tikz \graph [spring electrical layout, horizontal=0 to 1]
{ 0 [electric charge=5] -- subgraph C_n [n=10] };
"]],[["
\tikz \graph [spring electrical layout, horizontal=0 to 1]
{ [clique] 1 [electric charge=5], 2, 3, 4 };
"]]
examples = {
{
options = [["preamble={\usetikzlibrary{graphs,graphdrawing} \usegdlibrary{force}}"]],
code = [["
\tikz \graph [spring electrical layout, horizontal=0 to 1]
{ 0 [electric charge=1] -- subgraph C_n [n=10] };
"]]
},{
code = [["
\tikz \graph [spring electrical layout, horizontal=0 to 1]
{ 0 [electric charge=5] -- subgraph C_n [n=10] };
"]]
},{
code = [["
\tikz \graph [spring electrical layout, horizontal=0 to 1]
{ [clique] 1 [electric charge=5], 2, 3, 4 };
"]]
}
}
}

Expand Down
25 changes: 20 additions & 5 deletions tex/generic/pgf/lua/pgf/manual/DocumentParser.lua
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,17 @@ local function process_examples(t)

local n = {}
for i=1,#t do
n[i] = process_string(strip_quotes(t[i]))
local code, options
if type(t[i]) == "table" then
code = assert(t[i].code)
options = t[i].options
else
code = t[i]
end
n[i] = {
options = process_string(strip_quotes(options)),
code = process_string(strip_quotes(code))
}
end
return n
end
Expand Down Expand Up @@ -391,8 +401,9 @@ DocumentParser.addRenderer (
print_on_output(output,
"\\par\\smallskip\\emph{Example" .. (((#e>1) and "s") or "") .. "}\\par")
for _,example in ipairs(e) do
print_on_output(output, "\\begin{codeexample}[]")
print_lines_on_output(output, example)
local opts = table.concat(example.options or {}, "")
print_on_output(output, "\\begin{codeexample}[" .. opts .. "]")
print_lines_on_output(output, example.code)
print_on_output(output, "\\end{codeexample}")
end
end
Expand All @@ -417,8 +428,12 @@ DocumentParser.addRenderer (


function print_lines_on_output(output, lines)
for _,l in ipairs(lines or {}) do
output[#output+1] = l
for n,l in ipairs(lines or {}) do
if (n == 1 or n == #lines) and l == "" then
-- skip leading and trailing blank lines
else
output[#output+1] = l
end
end
end

Expand Down

0 comments on commit 6a0e08d

Please sign in to comment.