rgheck wrote:
One question: isn't it possible to handle this case like the other
external-material objects ?
I mean, imagine you define another kind of external-material object,
the "External Equation" type (e.g., a '*.eq' file), imagine you
associate a text editor to such a type, and imagine you define a set
of filters which just invoke externally LaTeX for computing the .eps
of the file for both preview and print purposes. This way, for
example, clicking on the image of the equation, would pop-up the
external text editor on the .eq file, and after exiting it would be
updated on the screen.
Wouldn't you achieve exactly what this user is looking for ?
In fact, the attached patch achieves such behaviour easily. If you have
a ".eq" file with a contents such as:
\begin{equation}
U = \frac{C}{T}
\end{equation}
then you can do Insert->File->External Material->[Equation (LaTeX)],
then select your .eq file. Now, if you have "Instant Preview" enabled in
preferences, you can see the formatted equation on the screen.
Furthermore, right-click on it and select "External Editor" and you can
edit it with emacs.
The difference w.r.t. an ERT block is that you can see the formatted
result on the screen (but editing through an external editor is not as
comfortable as a collapsable inset).
Was kind of a learning excercise -- just in case anyone finds such patch
useful (btw, I find the built-in LyX WYSIWYG/M equation editor
extraordinary).
T.
Index: lib/scripts/eq2eps.py
===================================================================
--- lib/scripts/eq2eps.py (revisione 0)
+++ lib/scripts/eq2eps.py (revisione 0)
@@ -0,0 +1,44 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# file eq2eps.py
+# This file is part of LyX, the document processor.
+# Licence details can be found in the file COPYING.
+#
+# \author Angus Leeming
+# \author Bo Peng
+# \author Tommaso Cucinotta
+#
+# Full author contact details are available in file CREDITS
+
+
+# This script converts a LaTeX equation (EQ) to Encapsulated PostScript (EPS).
+
+# Usage:
+# python eq2eps.py ${base}.eq ${base}.eps
+# This command generates
+# ${base}.eps the converted eps file
+
+import os, sys
+
+# We expect two args, the names of the input and output files.
+if len(sys.argv) != 3:
+ sys.exit(1)
+
+input, output = sys.argv[1:]
+
+# Fail silently if the file doesn't exist
+if not os.path.isfile(input):
+ sys.exit(0)
+
+# Strip the extension from ${input}
+inbase = os.path.splitext(input)[0]
+# Strip the extension from ${output}
+outbase = os.path.splitext(output)[0]
+
+# Generate the EPS file
+print 'latex -jobname=%s "\\documentclass{article}\\pagestyle{empty}\\begin{document}\\input{%s}\\end{document}"' % (inbase,input)
+if os.system('latex -jobname=%s "\\documentclass{article}\\pagestyle{empty}\\begin{document}\\input{%s}\\end{document}"' % (inbase,input)) != 0 or \
+ os.system('dvips -E -o %s.eps %s.dvi' % (outbase, inbase)) != 0:
+ print 'eq2eps fails'
+ sys.exit(1)
Index: lib/external_templates
===================================================================
--- lib/external_templates (revisione 33314)
+++ lib/external_templates (copia locale)
@@ -159,6 +159,35 @@
TemplateEnd
+Template Equation-LaTeX
+ GuiName "Eq: $$AbsOrRelPathParent$$Basename"
+ HelpText
+ A LaTeX Equation
+ HelpTextEnd
+ InputFormat eq
+ FileFilter "*.eq"
+ AutomaticProduction true
+ Transform Rotate
+ Transform Resize
+ Transform Clip
+ Transform Extra
+ Preview InstantPreview
+ Format LaTeX
+ TransformOption Rotate RotationLatexOption
+ TransformOption Resize ResizeLatexOption
+ TransformOption Clip ClipLatexOption
+ TransformOption Extra ExtraOption
+ Option Arg "[$$Extra,$$Rotate,$$Resize,$$Clip]"
+ Product "\\includegraphics$$Arg{$$AbsOrRelPathMaster$$Basename}"
+ UpdateFormat eps
+ UpdateResult "$$AbsPath$$Basename.eps"
+ Requirement "graphicx"
+ ReferencedFile latex "$$AbsPath$$Basename.eps"
+ ReferencedFile dvi "$$AbsPath$$Basename.eps"
+ FormatEnd
+TemplateEnd
+
+
Template ChessDiagram
GuiName "Chess: $$AbsOrRelPathParent$$Basename"
HelpText
Index: lib/configure.py
===================================================================
--- lib/configure.py (revisione 33314)
+++ lib/configure.py (copia locale)
@@ -507,6 +507,7 @@
\Format sweave Rnw "Sweave" S "" "%%" "document"
\Format lilypond ly "LilyPond music" "" "" "%%" "vector"
\Format latex tex "LaTeX (plain)" L "" "%%" "document"
+\Format eq eq "Equation (LaTeX)" L "" "%%" "document"
\Format pdflatex tex "LaTeX (pdflatex)" "" "" "%%" "document"
\Format xetex tex "LaTeX (XeTeX)" "" "" "%%" "document"
\Format text txt "Plain text" a "" "%%" "document"
@@ -585,6 +586,9 @@
def checkConverterEntries():
''' Check all converters (\converter entries) '''
+ addToRC(r'''\converter eq eps "python -tt $$s/scripts/eq2eps.py $$i $$o" ""
+''')
+
checkProg('the pdflatex program', ['pdflatex $$i'],
rc_entry = [ r'\converter pdflatex pdf2 "%%" "latex"' ])