Closed twsh closed 1 year ago
Sorry, I just realised that that will require all the different diagram generators to make PDF when the format is latex, and only tikz will be able to.
I should have added mimetype = "application/pdf"
.
I tried adding PDF output to convert_with_inkscape()
:
local function convert_with_inkscape(filetype)
-- Build the basic Inkscape command for the conversion
local inkscape_output_args
if filetype == 'png' then
inkscape_output_args = '--export-png="%s" --export-dpi=300'
elseif filetype == 'svg' then
inkscape_output_args = '--export-plain-svg="%s"'
elseif filetype == 'pdf' then
inkscape_output_args = '--export-type=pdf "%s"'
else
return nil
end
return function (pdf_file, outfile)
local inkscape_command = string.format(
'"%s" --without-gui --file="%s" ' .. inkscape_output_args,
inkscape_path,
pdf_file,
outfile
)
io.stderr:write(inkscape_command .. '\n')
local command_output = io.popen(inkscape_command)
-- TODO: print output when debugging.
command_output:close()
end
end
You can always use rsvg-convert or inkscape to convert svg to pdf. In fact there probably are tools which can convert between any two image formats you can think of. You will have to also add code so that you don't needlessly convert pdf > svg > pdf though. I would suggest creating some lookup tables in place of lots of if elseif else, since it is easier to maintain:
Where the "command" parts are functions which get passed the needed arguments and input as a table from which the function picks values to pass to the pipe function, then returns the same or another table with the "new info" like file names added which then can be passed on to the next function.
Yeah, I really like dispatch tables for tasks like this! :-) (And the tables returned by Lua filters are dispatch tables, so I'm probably preaching to the believers! :-)
-- Better --help|less than helpless
Den lör 21 nov. 2020 14:40Thomas Hodgson notifications@github.com skrev:
Sorry, I just realised that that will require all the different diagram generators to make PDF when the format is latex, and only tikz will be able to.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/pandoc/lua-filters/issues/145#issuecomment-731581053, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAI3OU5AWV5BYLRIY5QANLTSQ67LVANCNFSM4T5Y7CWQ .
@bpj That would be a big rewrite. Which is not to say that it's not a good idea.
I have a similiar request, to be able to just pass through the tikZ code if the target is LaTeX. That means, it will be rendered by the overall latex to pdf of the whole document with its settings. This avoids the multiple conversions back and forth.
@PeterSommerlad I like that idea. One problem that comes to mind is how to handle 'additionalPackages' attributes. At the moment, someone could be using different, incompatible, code for each of their tikz diagrams. One simple fix would be to note that this won't work, and that the user has to provide code in the header of their document suitable for all their diagrams.
i would just not output the additional packages in latex output mode and expect the latex template to handle those.
I have usually written something in the README along the lines of "It is up to you, the user, to make sure that the foo
package is loaded in your LaTeX template or in a header-includes
block in the metadata", followed by an example metadata snippet like
``````yaml
---
header-includes:
- |
```{=latex}
\usepackage{foo}
```
``````
That said it isn't all that hard to actually inject that block into metadata:
return {
{ Meta = function (meta)
if not meta['header-includes'] then
meta['header-includes'] = pandoc.MetaList()
end
-- Else assume it is a meta list and hope for the best
local hinc = meta['header-includes']
hinc[#hinc+1] = pandoc.MetaBlocks{
pandoc.RawBlock('latex', '\\usepackage{foo}')
}
return meta
end
},
main_filter,
}
The diagram generator is now maintained at https://github.com/pandoc-ext/diagram. The filter was rewritten to just use the generated PDF when converting to LaTeX or ConTeXt.
Currently, diagram-generator.lua uses makes svg images when latex is the target output. If I understand correctly, it would be better to just use the pdf directly when making tikz diagrams for LaTeX because svg is problematic with LaTeX. For other sorts of diagram, maybe png would be better, or also pdf.
I tried to do this, and it seems to work. Does it look like it will cause other problems?