yochju / latex-makefile

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

dot2tex support patch #46

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
dot2tex is a great piece of work that allows to create tex output using dot
(see "http://www.fauskes.net/code/dot2tex/", packaged insde debian/ubuntu)

The following is a patch to support it. (This is a diff with 2.1.23, but
reactualizing will be trivial)
There are currently some issues with it that stem from the fact that
dot2tex generates .tex files (analogous to .tex.sh), so one should take
care of not setting these as main targets. I wasn't successful in doing
this automatically. Also, there are problems if dot2tex files are placed
deeper than the main directory.

@@ -387,7 +387,7 @@
 # == LaTeX (tetex-provided) ==
 BIBTEX     := bibtex
 DVIPS      := dvips
-LATEX      := latex -src
+LATEX      := latex -src -shell-escape
 MAKEINDEX  := makeindex
 KPSEWHICH  := kpsewhich
 PS2PDF_NORMAL  := ps2pdf
@@ -663,6 +663,7 @@
 # Files of interest
 all_files.tex      := $(wildcard *.tex)
 all_files.tex.sh   := $(wildcard *.tex.sh)
+all_files.dot2tex  := $(wildcard *.dot2tex)
 all_files.rst      := $(wildcard *.rst)
 all_files.fig      := $(wildcard *.fig)
 all_files.gpi      := $(wildcard *.gpi)
@@ -698,6 +699,7 @@
 # Top level sources that can be built even when they are not by default
 files.tex  := $(filter-out %._gray_.tex,$(call filter-buildable,tex))
 files.tex.sh   := $(call filter-buildable,tex.sh)
+files.dot2tex  := $(call filter-buildable,dot2tex)
 files.rst  := $(call filter-buildable,rst)
 files.gpi  := $(call filter-buildable,gpi)
 files.dot  := $(call filter-buildable,dot)
@@ -715,6 +717,7 @@
 # Top level sources that are built by default targets
 default_files.tex  := $(filter-out %._gray_.tex,$(call filter-default,tex))
 default_files.tex.sh   := $(call filter-default,tex.sh)
+default_files.dot2tex  := $(call filter-default,dot2tex)
 default_files.rst  := $(call filter-default,rst)
 default_files.gpi  := $(call filter-default,gpi)
 default_files.dot  := $(call filter-default,dot)
@@ -727,15 +730,15 @@

 # Useful file groupings
 all_files_source   := $(call concat-files,tex,all)
-all_files_scripts  := $(call concat-files,tex.sh rst,all)
+all_files_scripts  := $(call concat-files,tex.sh rst dot2tex,all)
 all_files_graphics := $(call concat-files,fig gpi eps.gz dot,all)

 default_files_source   := $(call concat-files,tex,default)
-default_files_scripts  := $(call concat-files,tex.sh rst,default)
+default_files_scripts  := $(call concat-files,tex.sh rst dot2tex,default)
 default_files_graphics := $(call concat-files,fig gpi eps.gz dot,default)

 files_source   := $(call concat-files,tex)
-files_scripts  := $(call concat-files,tex.sh rst)
+files_scripts  := $(call concat-files,tex.sh rst dot2tex)
 files_graphics := $(call concat-files,fig gpi eps.gz dot)

 # Utility function for obtaining stems
@@ -745,6 +748,7 @@
 # List of all stems (including ._include_ and ._nobuild_ file stems)
 all_stems.tex      := $(call get-stems,tex,all)
 all_stems.tex.sh   := $(call get-stems,tex.sh,all)
+all_stems.dot2tex  := $(call get-stems,dot2tex,all)
 all_stems.rst      := $(call get-stems,rst,all)
 all_stems.fig      := $(call get-stems,fig,all)
 all_stems.gpi      := $(call get-stems,gpi,all)
@@ -755,6 +759,7 @@
 # List of all default stems (all default PDF targets):
 default_stems.tex      := $(call get-stems,tex,default)
 default_stems.tex.sh       := $(call get-stems,tex.sh,default)
+default_stems.dot2tex      := $(call get-stems,dot2tex,default)
 default_stems.rst      := $(call get-stems,rst,default)
 default_stems.fig      := $(call get-stems,fig,default)
 default_stems.gpi      := $(call get-stems,gpi,default)
@@ -764,6 +769,7 @@
 # List of all stems (all possible bare PDF targets created here):
 stems.tex      := $(call get-stems,tex)
 stems.tex.sh       := $(call get-stems,tex.sh)
+stems.dot2tex      := $(call get-stems,dot2tex)
 stems.rst      := $(call get-stems,rst)
 stems.fig      := $(call get-stems,fig)
 stems.gpi      := $(call get-stems,gpi)
@@ -775,7 +781,7 @@
 concat-stems   = $(sort $(foreach s,$1,$($(if $2,$2_,)stems.$s)))

 all_stems_source   := $(call concat-stems,tex,all)
-all_stems_script   := $(call concat-stems,tex.sh rst,all)
+all_stems_script   := $(call concat-stems,tex.sh rst dot2tex,all)
 all_stems_graphic  := $(call concat-stems,fig gpi eps.gz dot,all)
 all_stems_gray_graphic := $(addsuffix ._gray_,\
    $(all_stems_graphic) $(all_stems.eps) \
@@ -788,7 +794,7 @@
 all_stems_ssg      := $(sort $(all_stems_ss) $(all_stems_gray))

 default_stems_source   := $(call concat-stems,tex,default)
-default_stems_script   := $(call concat-stems,tex.sh rst,default)
+default_stems_script   := $(call concat-stems,tex.sh rst dot2tex,default)
 default_stems_graphic  := $(call concat-stems,fig gpi eps.gz dot,default)
 default_stems_gray_graphic := $(addsuffix ._gray_,$(default_stems_graphic))
 default_stems_gg   := $(sort \
@@ -800,7 +806,7 @@
 default_stems_ssg  := $(sort $(default_stems_ss) $(default_stems_gray))

 stems_source       := $(call concat-stems,tex)
-stems_script       := $(call concat-stems,tex.sh rst)
+stems_script       := $(call concat-stems,tex.sh rst dot2tex)
 stems_graphic      := $(call concat-stems,fig gpi eps.gz dot)
 stems_gray_graphic := $(addsuffix ._gray_,\
    $(stems_graphic) $(all_stems.eps))
@@ -1474,6 +1480,11 @@
 $(call colorize-dot-errors,$3)
 endef

+define convert-dot2tex
+$(DOT) -Txdot '$1' | dot2tex --figonly 2>'$3' > '$2'; \
+$(call colorize-dot-errors,$3)
+endef
+
 # Convert DVI to Postscript
 # $(call make-ps,<dvi file>,<ps file>,<log file>,[<paper size>])
 #original code
@@ -1706,6 +1723,10 @@
    $(QUIET)$(call echo-build,$<,$@)
    $(QUIET)$(call convert-rst,$<,$@)

+%.tex: %.dot2tex
+   $(QUIET)$(call echo-build,$^,$@)
+   $(QUIET)$(call convert-dot2tex,$<,$@,$<.log)
+
 #
 # GRAYSCALE LaTeX TARGETS
 #

Original issue reported on code.google.com by fdemes...@gmail.com on 18 Oct 2009 at 9:15

GoogleCodeExporter commented 9 years ago
A couple of comments:

1) You are right - there is no automatic way to avoid having .tex files be main 
targets, but you can name them like  mydotfile._include_.dot and get around it 
that 
way

2) Is there any reason you can't use the existing dot->eps facilities and 
include them 
as images?  One of the perils of using .tex file inclusion is that latex is 
really bad at 
notifying us that it ran into a dependency that it couldn't resolve (it doesn't 
work 
properly in batchmode, for example, so it requires multiple invocations to find 
all of 
the .tex includes, which frankly sucks).  So, we'd have to do some weird stuff 
to make 
it work (see ps_tex hacks in the makefile, for example).

Original comment by shiblon on 20 Oct 2009 at 6:19

GoogleCodeExporter commented 9 years ago
1) OK :)
2) No, there is no way to use the dot->eps toolchain. You probably don't know 
what
dot2tex does but one example is that it produces dot graphs that have nodes that
contain latex math. Obviously latex is needed somewhere in the loop.

Original comment by fdemes...@gmail.com on 20 Oct 2009 at 9:48

GoogleCodeExporter commented 9 years ago
Actually, you can use dot->eps and still get formulas and proper fonts in your 
node 
labels.  The way I have done this is by using the excellent psfrag module.

I'm pretty hesitant to include yet another tex-producing format, since so far 
all of the 
previous ones have been unmitigated disasters :(.  I do encourage you to look 
into 
psfrag.  It's pretty amazing, and has always worked wonders for me.

I can give examples if needed.

Original comment by shiblon on 21 Oct 2009 at 1:18

GoogleCodeExporter commented 9 years ago
Mmh, I didn't know about psfrag and it would probably have suit my needs... 
albeit it
looks like more of a hack... I understand though that you're reluctant to 
include
mainsteam support for dot2tex, so I'll keep my code for me :D

Original comment by fdemes...@gmail.com on 21 Oct 2009 at 1:30

GoogleCodeExporter commented 9 years ago
Question, then - how should this be invoked?

dot2tex infile.dot > outfile.dot_t

That's what I'm leaning toward.  Note that the makefile *can't* build these 
automatically 
for you.  It *can*, however, error out with a helpful instruction to call "make 
all-dot2tex" 
before proceeding, which is what I eventually had to do to support pstex.

Original comment by shiblon on 21 Oct 2009 at 1:47

GoogleCodeExporter commented 9 years ago
Hum, I'm not 100% sure what you are referring nor what you are implying with 
your
changes since I never used pstex.

The following is the correct way to invoke dot2tex.
$(DOT) -Txdot 'infile.dot' | dot2tex --figonly > 'outfile.tex';

And of course, inside your latex file: 
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}

and of course:
\input{outfile.tex}

Also note that my line above with the "latex -shell-escape" is not required

Original comment by fdemes...@gmail.com on 21 Oct 2009 at 2:10

GoogleCodeExporter commented 9 years ago
Regarding pstex, it's just a way to convert .fig files into .tex files 
(pstex_t, really).  So, 
it's pretty similar to this whole dot2tex idea, in that the final result is a 
set of tex 
commands.  Therefore, this approach has issues similar to that used for pstex.  
That's 
why I brought it up.

Looking at the dot2tex documentation, it appears that you can just do

$(DOT2TEX) 'infile.dot' > 'outfile.dot_t'

Note that I gratuitously changed .tex to .dot_t.  This makes it easier for 
people to 
differentiate between documents and graphic files.  You can still do 
\input{outfile.dot_t} and it works fine.

I am submitting a new revision to the head, and would like you to try it out.  
You'll 
have to change all of your \input{blah.tex} entries to be \input{blah.dot_t}, 
but that 
should be easy for you to do.  Try r62 and let me know what you think.

Original comment by shiblon on 21 Oct 2009 at 3:12

GoogleCodeExporter commented 9 years ago
Fixing issue dispenation.

Original comment by shiblon on 21 Oct 2009 at 7:17

GoogleCodeExporter commented 9 years ago
Impressive! It works really nicely.

I guess there's only one small fix I would add to your code: I would change all 
the
allfiles target to be user settable in the Makefile.ini  (aka change := to ?=)
The reason is that it enables people to have their own dot2tex files in another
directory than the root. Typically, I just did this for myself like this:
all_files.dot := $(wildcard *.dot) $(wildcard dot2tex/*.dot)
(and it works perfectly)

Original comment by fdemes...@gmail.com on 21 Oct 2009 at 11:38

GoogleCodeExporter commented 9 years ago
Excellent.  I am committing this and increasing the version number to 2.1.33.  
You can 
get this version as r64.

That version also fixes issue 47 (copying binaries to another directory).

Please update this bug if it works (or especially if it doesn't)!

Original comment by shiblon on 22 Oct 2009 at 1:29

GoogleCodeExporter commented 9 years ago
It works flawlessly.

Thanks for all the support. Your project is really a *GREAT* piece of work. I 
can't
stress enough how useful it is.

Original comment by fdemes...@gmail.com on 22 Oct 2009 at 1:35

GoogleCodeExporter commented 9 years ago
Excellent!  Hopefully you will continue being bold about submitting issues.  I 
want to 
continue improving it.

Original comment by shiblon on 22 Oct 2009 at 1:48