Monday, June 25, 2012

Using Elyxer to convert from Lyx to html

To create a html version of my thesis, I found Elyxer to be extremely convenient. I believe the only steps were as follows:
  1. Download Elyxer from here. (The current version when I downloaded it was 1.2.3)
  2. In a terminal, run
    cd elyxer-1.2.3/
    sudo ./install.py
  3. If you used \emph{<species name>} in your .bib file, see NOTE below.
  4. Go to the directory containing your lyx document (here I use "document.lyx") and create a subdirectory for elyxer to save output images (I used htmlImages).
  5. In a terminal, run
    elyxer.py --destdirectory "htmlImages" --title "<title of html page>" document.lyx <name of the output>.html
  6. Move the html file to the destination directory.
  7. Double click the html file to view a nicely formatted and linked version of your lyx file!
NOTE: Elyxer cannot handle \emph{...} in the bibtex bibliography files. It was a bit of a pain to fix this, as the output html file eliminates the second }, making searching and replacing with <i> and </i> tags impossible. To overcome this, I followed these steps:
  1. Download the plugin for regular expression search and replace using gedit from here:
    1. Download and extract the files (found here).
    2. Move those files to ~/.gnome2/gedit/plugins/ :
      cd .gnome2/gedit/
      mkdir plugins
      cd plugins/
      mv /home/peter/Downloads/regex_replace ./
      mv /home/peter/Downloads/regex_replace.gedit-plugin ./
    3. Close gedit
    4. Open gedit, choose Preferences from the Edit menu. On the plugins tab, you should see Regular Expression Replace in the list. Check to enable. Now, you should have a "Regular Expression" item in the Search menu.
  2. open your bibtex file(s), and save a new copy (this will mess up the pdf output of your lyx document).
  3. In the regular expression search box, search for \\emph\{([a-zA-Z_1-9 ]*)(\}) and replace with <i>\1</i>
  4. This will probably miss some cases of \emph{...}, so do a final search for \emph using gedit's search feature and fix them by hand. (The [a-zA-Z_1-9 ] term only finds those characters, so expressions with linebreaks or other odd characters get skipped. This could be fixed if it is too big of a problem.)
  5. Open your lyx document, save as a new copy (again, we don't want to screw up the working pdf output) and change the bibtex files to our new versions. (Click on BibTeX Generated Bibliography, delete the existing bibtex files, then add the new ones.)

1 comment:

Zcam said...

Can this working also on windows?