yochju / latex-makefile

Automatically exported from code.google.com/p/latex-makefile
Other
0 stars 0 forks source link

create gaphics with inkscape & export-id #122

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Sometimes you don't want to export the whole svg to pdf. Here is way to do it ;)

create files with shema:
svg.svgid and the filename as content

Makefile.ini:
# $(call run-inkscape-id,<master svg>,<id>,<to>)
run-inkscape-id = $(INKSCAPE) $1 -z -j --export-id=$2 --export-pdf=.tmp.$2.pdf; 
\
                $(MV) .tmp.$2.pdf $3.pdf

%.pdf: %.svgid main.svg
        $(QUIET)$(call run-inkscape-id, `cat $<`,`basename $@ .pdf`,`dirname $@`/`basename $@ .pdf`)

this main.svg is the svg where all the ids are - this is a bad hack, any nice 
solution? the right file would be `cat $<`?

now you have to add the svgid as graphic extension in Makefile:

graphic_source_extensions       += eps svgid

One question, is there a way to modify graphic_source_extensions in 
Makefile.ini? a post Makefile.ini?

Original issue reported on code.google.com by sandrokn...@gmail.com on 4 Apr 2011 at 10:13

Attachments:

GoogleCodeExporter commented 9 years ago
Interesting.  So, to be sure I understand this, you create an SVG document with 
various parts of it tagged with their own IDs.  Then you want to render each 
part as its own graphic?

So, the proposal is to create a new type of file that contains the ID of the 
.svg part that you care about.  We could do even better than this, really, and 
create a .svgid file that points to the file and specifies the ID, where the 
contents might be something like

file-with-everything.svg
ID=3

Then the makefile can generate appropriate dependencies by parsing this.  Once 
it has the dependencies, the rest is pretty simple to do.

Regarding the graphic_source_extensions, no, you can't fiddle with that in 
Makefile.ini.  As a general rule, if it isn't exposed explicitly for 
Makefile.Ini, it is very brittle to rely on it - it's internal implementation 
only.  To test this out, you don't really need do alter 
graphic_source_extensions, anyway.

Here's what I suggest you try (without giving full details, as I'm rushing off 
to do some work, now):

- Determine a reasonable format for your svgid file, perhaps key=value pairs, 
allowing # comment leaders, e.g.,

  # Pick the foo from the bar file
  filename=bar.svg
  id=3

- Find all .svgid files

  all_svgid = $(wildcard *.svgid)
  all_svgid_targets = $(all_svgid:.svgid=.pdf)
  all_svgid_d = $(all_svgid:.svgid=.d)

- Create a target that converts from .svgid to .pdf, and depends on a 
dependencies file, e.g.,

  $(all_svgid_targets): %.pdf: %.svgid %.d
    inkscape `sed -n -e 's/filename=//p' $<` -z -j --export-id=`sed -n -e 's/id=//p' $<` --export-pdf=$@ 

- Include all possible dependency files, e.g.,

  -include $(all_svgid_d)

- Create a rule to actually make those dependency files (this is probably 
incomplete):

  $(all_svgid_d): %.d: %.svgid
     sed -e 's/filename=\(.*\)/$*.pdf: \1/p' -e 'd' $< > $@

So, did that make sense?  Basically, since you are depending on a file that is 
not the ultimate source file, you have to automatically generate the 
dependencies for it.  So, we have .svgid .d - > .pdf, and it notices that there 
is no .d file, so it runs the target .svgid -> .d, which adds the true .svg 
file to the dependencies for that particular .pdf file.  Armed with that 
information, make now knows that it needs %.svgid %.d, and bar.svg to generate 
%.pdf.

Then we have, in our inkscape command, two sed invocations that parse the 
.svgid and provide the necessary arguments to inkscape.

It's not super simple, but this is how you get all of your dependencies 
robustly specified without having to hard-code the name of the source file for 
your svg ids.

Let me know how that works for you, and maybe we can include this in the 
makefile.  At the very least, it's probably time to start doing a real wiki for 
this project, and we can put it up there as a recipe.

Original comment by shiblon on 6 Apr 2011 at 6:03