On 14.08.2009, at 15:56, Pavel Sanda wrote:

Daniel Lohmann wrote:
Or am I mistaken here? I am still seeking for a definite answer regarding the conversion route that to my understanding is automatically deduced by LyX (TiKZ --> PDF | PDF --> Preview). It seem that (newer?) versions of LyX just pass everything right through to ImageMagik and do not bother with
deducing a conversion route?

without looking into the code, creating tikz->png convertor wont help?
pavel

Just to close this thread:

Defining an additional tikz->png converter does indeed solve the problem. Another possible solution is to extend the convertDefault.py script to recognize "TikZ:" as input format. For convenience reasons, this is the route I have been taking.


If others would like to try this: Here are the step-by-step instructions:

-- Under [File Handling --> File formats] add a new file format "TikZ" as Vector graphics format, Short Name: "Tikz", Extension: "tikz", and Editor: "vim".

-- Under [File Handling --> Converters] add a Converter Definition "TikZ --> PDF (ps2pdf)" with Converter: "pdflatex - interaction=nonstopmode $$i"

-- Replace the convertDefault.py script by the attached version.

Disclaimer: This are my very first lines of Python code!

Note: According to the docs, it should be enough to put the customized version of convertDefault.py into $LYXUSER/scripts (~/Library/ Application Support/Lyx-1.x on the Mac). However, on my system (Mac OS X, LyX 1.6.3) it seems to remain unrecognized in this position, so I ended up with replacing the default version.


Daniel



#!/usr/bin/env python
# -*- coding: utf-8 -*-

# file convertDefault.py
# This file is part of LyX, the document processor.
# Licence details can be found in the file COPYING.

# \author Herbert Voß
# \author Bo Peng

# Full author contact details are available in file CREDITS.

# The default converter if no other has been defined by the user from the
# Conversion->Converter tab of the Preferences dialog.

# The user can also redefine this default converter, placing their
# replacement in ~/.lyx/scripts

# converts an image from $1 to $2 format
import os, re, sys

# We may need some extra options only supported by recent convert versions
re_version = re.compile(r'^Version:.*ImageMagick\s*(\d*)\.(\d*)\.(\d*).*$')
fout = os.popen('convert -version 2>&1')
output = fout.readline()
fout.close()
version = re_version.match(output)
major = int(version.group(1))
minor = int(version.group(2))
patch = int(version.group(3))
version = hex(major * 65536 + minor * 256 + patch)

opts = "-depth 8"

# DL: If input format is "TikZ" convert it to pdf first by calling pdflatex 
#     then use the generated pdf as input to ImageMagik's convert
if sys.argv[1][:5].lower() == 'tikz:':
    if os.system(r'pdflatex -interaction=nonstopmode "%s"' % (sys.argv[1][5:])) != 0:
        print >> sys.stderr, sys.argv[0], 'ERROR'
        print >> sys.stderr, 'Execution of "pdflatex" failed.'
        sys.exit(1)

    # Now use the generated pdf as input format.
    sys.argv[1] = "pdf:"+sys.argv[1][5:-4]+"pdf"

# If supported, add the -define option for pdf source formats 
if sys.argv[1][:4] == 'pdf:' and version >= 0x060206:
    opts = '-define pdf:use-cropbox=true ' + opts

# If supported, add the -flatten option for ppm target formats (see bug 4749)
if sys.argv[2][:4] == 'ppm:' and version >= 0x060305:
    opts = opts + ' -flatten'

if os.system(r'convert %s "%s" "%s"' % (opts, sys.argv[1], sys.argv[2])) != 0:
    print >> sys.stderr, sys.argv[0], 'ERROR'
    print >> sys.stderr, 'Execution of "convert" failed.'
    sys.exit(1)



Reply via email to