On 18. okt. 2011 18:39, Wei-Dong Lian wrote:
hi everyone,

I am adapting the tikz figures into lyx. I can generate tikz codes in
a separated file, name with *.tikz.
The idea is to generate tikz codes for drawing in each file but control
their styles globally. The line width, font size, colors or other styles
will be consistent throughout the whole document. Even if in several
generated tikz files you want special style, you can just modify that
file and suppress the global style options.

Now if in latex, we can replace 'includegraphics' with 'input' in the
following tex code. it works well.
*******************************************************************************
\begin{figure}[h]
   \centering
   \includegraphics{}
   \caption{caption}
   \label{"waiting for reftex-label call..."}
\end{figure}
***********************************************************************************
But in lyx, we need to add ERT code 'input{*.tikz}' for each figure.
This is not consistent with the Insert Graphics of Lyx. So I want still
use the Insert Graphics in lyx to treat tikz as a image file as *.eps,
*.png.

Tikz files can be included without ERT - at least files made with qtikz.

I wonder if we could redefine the \includegraphics{*.tikz} to
input{*.tikz} for the specific extension file, Or  from the FileFormat
Settings for tikz in the preference dialog, does it exist some possible
solutions for tikz?


In LyX:
First, add tikz support to the document preamble:
Document->settings->LaTeX Preamble
Type this in the box:
\usepackage{tikz}
Also add any \usetikzlibrary stuff you need.

Then, to insert a tikz file in the main window:
Insert->File->Child Document

You will get a dialog. This can be used to insert lyx or tex files. And a tikz file is really a tex file. So:
Type in the filename of your tikz file. e.g. filename.tikz
Use the include type "input" to get the tikz figure right there, or
the include type "include" to get the tikz figure on a new page.

This works for me, at least for tikz files like this one:
\begin{tikzpicture}
grow=down

\node (test) [shape=circle,draw] {
  test
}
child {node [shape=circle,draw] {b}}
child {node [shape=rectangle,draw] {a}};

\end{tikzpicture}

tikz code can also be written directly into an ERT box, if you
want to have the image embedded in the LyX file instead of
in a file of its own.

Helge Hafting

Reply via email to