The attached patch should finally make HTML export work properly. Various approaches to doing this were discussed on the list a while ago:
   http://www.mail-archive.com/lyx-devel@lists.lyx.org/msg118138.html
It eventually occurred to me, however, that the cleanest solution was probably to use the copier mechanism that is already available, which is what this patch does, rather than to put special handling for this kind of thing into the code in Converter.cpp. And of course, this makes the behavior user-configurable, in principle.

I've added two scripts: a dir_copy.py script, that simply copies the entire temporary directory over to a subdirectory of the intended output directory, and a tex4html_copy.py script that copies only .png, .html, and .css files, these (I'm pretty sure) being the only kinds of files generated by htlatex. What happens, in the end, then, is that if you open /path/to/file/LyXFile.lyx and do File>Export>HTML, then you end up with a (possibly new) directory /path/to/file/LyXFile.html.LyXconv/ and all the relevant files are in there. Rather, say, than scattered across /path/to/file/, which would make it a hassle then to move them to a webserver.

I've then updated configure.py so that it adds tex4html_copy.py as a copier for both the html and htmlword formats if htlatex is found, and adds dir_copy.py as a copier for the former if latex2html is found instead. The latter could be refined or changed. I don't know exactly what latex2html spits out.

Testing on Windows would be nice. I believe this should fix bug 3090, since the HTML conversion will be done in LyX's temporary directory and so won't need pathnames.

I know it's late for this, but (a) it's been discussed a fair bit, (b) this isn't messing with central LyX code, and (c) it would be really nice if this would work for a change, since "HTML" sits there on the menu looking so enticing....

Seeking the OK to commit.

Richard

--
==================================================================
Richard G Heck, Jr
Professor of Philosophy
Brown University
http://frege.brown.edu/heck/
==================================================================
Get my public key from http://sks.keyserver.penguin.de
Hash: 0x1DE91F1E66FFBDEC
Learn how to sign your email using Thunderbird and GnuPG at:
http://dudu.dyn.2-h.org/nist/gpg-enigmail-howto

Index: lib/scripts/tex4html_copy.py
===================================================================
--- lib/scripts/tex4html_copy.py	(revision 0)
+++ lib/scripts/tex4html_copy.py	(revision 0)
@@ -0,0 +1,74 @@
+#! /usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# file tex_copy.py
+# This file is part of LyX, the document processor.
+# Licence details can be found in the file COPYING.
+
+# author Angus Leeming
+# author Georg Baum
+# author Richard Heck
+
+# Full author contact details are available in file CREDITS
+
+# Usage:
+# tex4html_copy.py <from file> <to file>
+
+# This script is to be used as a "copier" script in the sense needed by
+# the converter definitions. Given a <from file> and <to file>, it will
+# copy all the files that might have been generated by a tex4ht-type HTML
+# conversion form LyX's temporary directory to a subdirectory of the directory 
+# in which <to file> was to have appeared. The files copied are .html, .css,
+# and .png files.
+
+
+import os, sys
+
+from lyxpreview_tools import error
+
+
+def usage(prog_name):
+    return "Usage: %s <from file> <to file>" % prog_name
+
+
+def main(argv):
+    # Parse and manipulate the command line arguments.
+    if len(argv) != 3:
+        error(usage(argv[0]))
+
+    # input file
+    abs_from_file = argv[1]
+    if not os.path.isabs(abs_from_file):
+        error("%s is not an absolute file name.\n%s"\
+              % abs_from_file, usage(argv[0]))
+    from_dir = os.path.dirname(abs_from_file)
+
+    # output_dir will be filename.ext.conversion
+    to_dir = argv[2] + ".LyXconv"
+
+    # check if the output directory exists
+    if not os.path.isdir(to_dir):
+      try:
+        os.makedirs(to_dir)
+      except:
+        error("Unable to create %s" % to_dir)
+    
+    import shutil
+    
+    # copy all files in from_dir to to_dir
+    extensions = ['.html', '.png', '.css']
+    for file in os.listdir(from_dir):
+      junk, ext = os.path.splitext(os.path.basename(file))
+      ext = ext.lower()
+      try:
+        extensions.index(ext)
+        from_file = os.path.join(from_dir, file)
+        to_file  = os.path.join(to_dir, file)
+        shutil.copy(from_file, to_file)
+      except:
+        pass
+      
+    return 0
+
+if __name__ == "__main__":
+    main(sys.argv)
Index: lib/scripts/dir_copy.py
===================================================================
--- lib/scripts/dir_copy.py	(revision 0)
+++ lib/scripts/dir_copy.py	(revision 0)
@@ -0,0 +1,68 @@
+#! /usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# file tex_copy.py
+# This file is part of LyX, the document processor.
+# Licence details can be found in the file COPYING.
+
+# author Angus Leeming
+# author Georg Baum
+# author Richard Heck
+
+# Full author contact details are available in file CREDITS
+
+# Usage:
+# dir_copy.py <from file> <to file>
+
+# This script is to be used as a "copier" script in the sense needed by
+# the converter definitions. Given a <from file> and <to file>, it will in
+# fact copy the entire contents of the directory (normally, LyX's temporary
+# directory) to a subdirectory of the directory in which <to file> would have
+# appeared. The copier may be used with converters that produce a lot of files
+# and where there is no reliable way to know which files, precisely, need to
+# be copied over. So you just copy everything.
+
+
+import os, sys
+
+from lyxpreview_tools import error
+
+
+def usage(prog_name):
+    return "Usage: %s <from file> <to file>" % prog_name
+
+
+def main(argv):
+    # Parse and manipulate the command line arguments.
+    if len(argv) != 3:
+        error(usage(argv[0]))
+
+    # input file
+    abs_from_file = argv[1]
+    if not os.path.isabs(abs_from_file):
+        error("%s is not an absolute file name.\n%s"\
+              % abs_from_file, usage(argv[0]))
+    from_dir = os.path.dirname(abs_from_file)
+
+    # output_dir will be filename.ext.conversion
+    to_dir = argv[2] + ".LyXconv"
+
+    # check if the output directory exists
+    if not os.path.isdir(to_dir):
+      try:
+        os.makedirs(to_dir)
+      except:
+        error("Unable to create %s" % to_dir)
+    
+    import shutil
+    
+    # copy all files in from_dir to to_dir
+    for file in os.listdir(from_dir):
+      from_file = os.path.join(from_dir, file)
+      to_file  = os.path.join(to_dir, file)
+      shutil.copy(from_file, to_file)
+      
+    return 0
+
+if __name__ == "__main__":
+    main(sys.argv)
Index: lib/configure.py
===================================================================
--- lib/configure.py	(revision 18769)
+++ lib/configure.py	(working copy)
@@ -347,8 +347,19 @@
     checkProg('an MS Word -> LaTeX converter', ['wvCleanLatex $$i $$o'],
         rc_entry = [ r'\converter word       latex      "%%"	""' ])
     #
-    checkProg('a LaTeX -> MS Word converter', ["htlatex $$i 'html,word' 'symbol/!' '-cvalidate'"],
+    path, htlatex = checkProg('a LaTeX -> HTML converter', ['htlatex $$i', 'tth  -t -e2 -L$$b < $$i > $$o', \
+        'latex2html -no_subdir -split 0 -show_section_numbers $$i', 'hevea -s $$i'],
+        rc_entry = [ r'\converter latex      html       "%%"	"needaux"' ])
+    if htlatex == 'htlatex':
+      addToRC(r'''\copier    html       "python -tt $$s/scripts/tex4html_copy.py $$i $$o"''')
+    else:
+      addToRC(r'''\copier    html       "python -tt $$s/scripts/dir_copy.py $$i $$o"''')
+
+    #
+    path, htlatex = checkProg('a LaTeX -> MS Word converter', ["htlatex $$i 'html,word' 'symbol/!' '-cvalidate'"],
         rc_entry = [ r'\converter latex      wordhtml   "%%"	"needaux"' ])
+    if htlatex == 'htlatex':
+      addToRC(r'''\copier    wordhtml   "python -tt $$s/scripts/tex4html_copy.py $$i $$o"''')
     #
     checkProg('an OpenOffice.org -> LaTeX converter', ['w2l -clean $$i'],
         rc_entry = [ r'\converter sxw        latex      "%%"	""' ])
@@ -358,10 +369,6 @@
     #
     checkProg('a LaTeX -> Open Document converter', ['oolatex $$i', 'oolatex.sh $$i'],
         rc_entry = [ r'\converter latex      odt        "%%"	"latex"' ])
-    #
-    #FIXME Looking for the commands needed to make oolatex output sxw instad of odt...
-    #checkProg('a LaTeX -> OpenOffice.org (sxw) converter', ['oolatex $$i', 'oolatex.sh $$i'],
-    #    rc_entry = [ r'\converter latex      odt        "%%"	"latex"' ])
     # On windows it is called latex2rt.exe
     checkProg('a LaTeX -> RTF converter', ['latex2rtf -p -S -o $$o $$i', 'latex2rt -p -S -o $$o $$i'],
         rc_entry = [ r'\converter latex      rtf        "%%"	"needaux"' ])
@@ -429,9 +436,6 @@
 \converter agr        ppm        "gracebat -hardcopy -printfile $$o -hdevice PNM $$i 2>/dev/null"	""''',
             ''])
     #
-    checkProg('a LaTeX -> HTML converter', ['htlatex $$i', 'tth  -t -e2 -L$$b < $$i > $$o', \
-        'latex2html -no_subdir -split 0 -show_section_numbers $$i', 'hevea -s $$i'],
-        rc_entry = [ r'\converter latex      html       "%%"	"needaux"' ])
     #
     path, lilypond = checkProg('a LilyPond -> EPS/PDF/PNG converter', ['lilypond'])
     if (lilypond != ''):
Index: development/scons/scons_manifest.py
===================================================================
--- development/scons/scons_manifest.py	(revision 18769)
+++ development/scons/scons_manifest.py	(working copy)
@@ -2729,6 +2729,7 @@
     clean_dvi.py
     convertDefault.py
     date.py
+    dir_copy.py
     fen2ascii.py
     fig2pdftex.py
     fig2pstex.py
@@ -2739,6 +2740,7 @@
     lyxpreview2bitmap.py
     lyxpreview_tools.py
     tex_copy.py
+    tex4html_copy.py
 ''')
 
 
Index: lib/Makefile.am
===================================================================
--- lib/Makefile.am	(revision 18769)
+++ lib/Makefile.am	(working copy)
@@ -1017,6 +1017,7 @@
 	scripts/clean_dvi.py \
 	scripts/convertDefault.py \
 	scripts/date.py \
+	scripts/dir_copy.py \
 	scripts/fen2ascii.py \
 	scripts/fig2pdftex.py \
 	scripts/fig2pstex.py \
@@ -1026,7 +1027,8 @@
 	scripts/listerrors \
 	scripts/lyxpreview2bitmap.py \
 	scripts/lyxpreview_tools.py \
-	scripts/tex_copy.py
+	scripts/tex_copy.py \
+	scripts/tex4html_copy.py
 
 templatesdir = $(pkgdatadir)/templates
 dist_templates_DATA = \

Reply via email to