# Author: Chris Karakas # http://www.karakas-online.de # # Part of the LyX-to-X project. # See http://www.karakas-online.de/mySGML/ for a detailed # description. # # Copyright (c) 2004, Chris Karakas # http://www.karakas-online.de # chris at mydomain dot de (see above for my domain) # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; see the file COPYING. If not, write to # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. # Valid only for LyX v. 1.6.x # Substitute with # s/]*\)><\/link>//g # Valid only for LyX v. 1.2.x # # Substitute with # Not a really good idea, so leave it commented. # If you decide to use it, you will be able to # cross-reference to an arbitrary point in your # document, not just sections and chapters! # BUT: The link will not be of the form # "Section something" - it will be just the # word "here" in hyperlink form... # That's why I say it is not a really good idea. # But perhaps you could elaborate on this... # # s/]*\)>/here<\/link>/g # Valid only for LyX v. 1.2.0 # Substitute # # some title <anchor id="some label" > # # with # # <sect1 id="some label" ><title>some title # # also substitute # # <chapter><title> some title <anchor id="some label"> # # with # # <chapter id="somelabel"><title> some title s/<\(sect[^>]*\)>\(<title>[^<]*\)<anchor \([^>]*\)>/<\1 \3>\2/g s/<\(chapter\)>\(<title>[^<]*\)<anchor \([^>]*\)>/<\1 \3>\2/g # Valid only for LyX v. 1.6.x # Substitute # # <sect1> # <title> # some title <anchor id="some label" ></anchor> # # with # # <sect1 id="some label" > # <title> # some title # # /^[^<]*<sec/{ # N # N # s/<\(sect[^>]*\)>\([ \t\n\r]*<title>[ \n]*[^<]*\)<anchor \([^>]*\)><\/anchor>/<\1 \3>\2/ # P # D # } # Valid only for LyX v. 1.6.x # Substitute <graphic> with the more elaborate # <mediaobject> # <![ %output.print.png; [ # <imageobject> # <imagedata fileref="./images/\1.png" format="PNG"> # </imageobject> # ]]> # <![ %output.print.pdf; [ # <imageobject> # <imagedata fileref="\1.pdf" format="PDF" scale="65"> # </imageobject> # ]]> # <![ %output.print.eps; [ # <imageobject> # <imagedata fileref="\1.eps" format="EPS"> # </imageobject> # ]]> # <textobject> # <phrase>Figure</phrase> # </textobject> # </mediaobject> # # where \1 is the matched image filename without the extension. ########################################################################################### # s/<graphic fileref="\([^"]*\)"><\/graphic>/ <mediaobject>\ # <\!\[ \%output\.print\.png; \[\ # <imageobject>\ # <imagedata fileref="\.\/images\/\1.png" format="PNG">\ # <\/imageobject>\ # \]\]>\ # <\!\[ \%output\.print\.pdf; \[\ # <imageobject>\ # <imagedata fileref="\1.pdf" format="PDF" scale="65">\ # <\/imageobject>\ # \]\]>\ # <\!\[ \%output\.print\.eps; \[\ # <imageobject>\ # <imagedata fileref="\1.eps" format="EPS">\ # <\/imageobject>\ # \]\]>\ # <textobject>\ # <phrase>Figure<\/phrase>\ # <\/textobject>\ # <\/mediaobject>/g # } # Valid only for LyX v. 1.2.0 # Substitute <graphic> with the more elaborate # <mediaobject> # <![ %output.print.png; [ # <imageobject> # <imagedata fileref="./images/\1.png" format="PNG"> # </imageobject> # ]]> # <![ %output.print.pdf; [ # <imageobject> # <imagedata fileref="\1.pdf" format="PDF" scale="65"> # </imageobject> # ]]> # <![ %output.print.eps; [ # <imageobject> # <imagedata fileref="\1.eps" format="EPS"> # </imageobject> # ]]> # <textobject> # <phrase>Figure</phrase> # </textobject> # </mediaobject> # # where \1 is the matched image filename without the extension. ########################################################################################### /^.*<figure><title><graphic/{ s/<figure><title><graphic fileref="\([^"]*\)">[ ]*<anchor id="\([^"]*\)">\([^<]*\)<\/title>[ ]*<\/figure>/\ <figure id="\2" float="1">\ <title>\ \3\ <\/title>\ <mediaobject>\ <\!\[ \%output\.print\.png; \[\ <imageobject>\ <imagedata fileref="\.\/images\/\1.png" format="PNG">\ <\/imageobject>\ \]\]>\ <\!\[ \%output\.print\.pdf; \[\ <imageobject>\ <imagedata fileref="\1.pdf" format="PDF">\ <\/imageobject>\ \]\]>\ <\!\[ \%output\.print\.eps; \[\ <imageobject>\ <imagedata fileref="\1.eps" format="EPS">\ <\/imageobject>\ \]\]>\ <\!\[ \%output\.print\.bmp; \[\ <imageobject>\ <imagedata fileref="\1.bmp" format="BMP">\ <\/imageobject>\ \]\]>\ <textobject>\ <phrase>\3<\/phrase>\ <\/textobject>\ <caption>\ <para>\3<\/para>\ <\/caption>\ <\/mediaobject>\ <\/figure>\ /g } /^.*[^<]*<graphic/{ s/<graphic fileref="\([^"]*\)">/\ <mediaobject>\ <\!\[ \%output\.print\.png; \[\ <imageobject>\ <imagedata fileref="\.\/images\/\1.png" format="PNG">\ <\/imageobject>\ \]\]>\ <\!\[ \%output\.print\.pdf; \[\ <imageobject>\ <imagedata fileref="\1.pdf" format="PDF">\ <\/imageobject>\ \]\]>\ <\!\[ \%output\.print\.eps; \[\ <imageobject>\ <imagedata fileref="\1.eps" format="EPS">\ <\/imageobject>\ \]\]>\ <\!\[ \%output\.print\.bmp; \[\ <imageobject>\ <imagedata fileref="\1.bmp" format="BMP">\ <\/imageobject>\ \]\]>\ <textobject>\ <phrase>Figure<\/phrase>\ <\/textobject>\ <\/mediaobject>/g } # This will not work, if you have both program code and images # that you want to include from LyX! # # /^.*[^<]*<inlinegraphic/{ # s/<inlinegraphic fileref="\([^"]*\)"[^>]*>/\ # <inlinemediaobject>\ # <\!\[ \%output\.print\.png; \[\ # <imageobject>\ # <imagedata fileref="\.\/images\/\1.png" format="PNG">\ # <\/imageobject>\ # \]\]>\ # <\!\[ \%output\.print\.pdf; \[\ # <imageobject>\ # <imagedata fileref="\1.pdf" format="PDF" scale="65">\ # <\/imageobject>\ # \]\]>\ # <\!\[ \%output\.print\.eps; \[\ # <imageobject>\ # <imagedata fileref="\1.eps" format="EPS">\ # <\/imageobject>\ # \]\]>\ # <\!\[ \%output\.print\.bmp; \[\ # <imageobject>\ # <imagedata fileref="\1.bmp" format="BMP">\ # <\/imageobject>\ # \]\]>\ # <textobject>\ # <phrase>Inline graphic<\/phrase>\ # <\/textobject>\ # <\/inlinemediaobject>/g # } # Valid only for both LyX v. 1.6.x and LyX v. 1.2.0 # Substitute <programmlisting> with <screen> /^.*[^<]*<programlisting/s/<programlisting\([^>]*\)>/<screen\1>/g /^.*[^<]*<\/programlisting>/s/<\/programlisting\([^>]*\)>/<\/screen\1>/g # Enclose <tgroup> </tgroup> pairs in # <table frame=all> </table> pairs # /^[^<]*<tgroup/s/\(<tgroup\)/<table frame=all> \1/ # /^[^<]*<\/tgroup>/s/\(<\/tgroup>\)/\1\ # <\/table>/ # Delete the <para> tag before the <tgroup> tag # and prepend <table>. # /^[^<]*<para>/{ # N # s/<para>\([ \t\n\r]*<tgroup[^>]*\)>/<table frame=all>\ # <title>Sample Table<\/title>\ # \1>/ # P # D # } # Delete the <para> before the <tgroup> tag. s/<para><tgroup/<tgroup/g # Delete the </para> after the </tgroup> tag. s/<\/tgroup><\/para>/<\/tgroup>/g # For table captions and titles to be output correctly, # you have to eliminate the <para> from any sequence # # AND you have to write a table float, in the inside of # which you will have to set the title and the caption # environment on one line, then press , set the # environment to "Standard" (this will produce the # element we eliminate here) and continue with # the table normally. A warning about an # "end tag for element "TABLE" which is not open" # is the less evil we can get and is harmless # (a LyX bug in 1.2.0, not openjade's) /<\/title><anchor id="some id"> # # with # # <table id="some id"><title> s/<table>[ ]*<title>[ ]*<anchor \([^>]*\)>/<table \1><title>/g # Delete one </listitem> in </para></listitem></listitem>. s/<\/para><\/listitem><\/listitem>/<\/para><\/listitem>/g # Substitute 'ldquo' with 'quot' and 'rdquo' with 'quot' too. # s/“/\"/g # s/”/\"/g # # Substitute quotes with <quote> tags. # Depending on the language attribute (lang="...") # of the elements (<book lang="fr">, for example), they are # rendered differently (e.g. with guillemets in french). # The spaces in the regexps avoid markup like # <othercredit role="converter"> # where such substitution would be detrimental. s/[ ,]+“/ <quote>/g s/”[ ,]+/<\/quote> /g # But we are not done with the quots yet :-( # In <othercredit> we have to substitute # # " # # with # # " # /<othercredit/s/\"/"/g /<othercredit/s/\”/"/g # Substitute &copy; with ©. This will produce a # Copyright symbol, instead of "©". s/&copy;/\©/g # Also, substitute &xxxx; with the character it representes. # Somehow these entities do not work. s/[/[/g s/]/]/g s/{/{/g s/}/}/g s/$/$/g s/%/%/g s/#/#/g s/|/|/g s/£/£/g s/_/_/g s/\/\\/g s/˜/~/g # Substitute # # </para><para> <----- at the END of a line! # <equation> # # to # # </para><para> # <informalequation> # # We do this only to MARK the start of a *displayed* # (as opposed to *inline*) equation. # Don't bother that we named it "informalequation". # We could have neamed it "whatever". # In the AWK script awkscr_math, we will convert it # back, but only after we have transformed the rest # from <equation> to <inlineequation>. # Because, that's the trick, everything that is # still called "equation" *after* the change below, # it is actually an *inlineequation*!! /<\/para><para>$/{ N s/[ \t\n\r]*<equation>/\ <informalequation>/ p d } # /^<para>$/{ # N # s/[ \t\n\r]*<equation>/\ # <informalequation>/ # p # d # } # Insert a newline after the $ that follows the # <alt> element of an equation. Thus, <alt>$ will stay # on one line - and this makes processing with # awkscr_math easier: we can then check if $0 (which # is the current line in awk) contains "<alt>$" - and skip it. s/<alt>\$/<alt>\$\ /g # For Citations: # Substitute # # <xref linkend="cit:someID"> # # with # # <citation role="REFDB">someID</citation> # # Important: we use the *short* notation, # because we cannot distinguish between the first and # the subsequent occurences of a citation. s/<xref linkend="cit:\([^"]*\)">/\ <citation role="REFDB">\1<\/citation>\ /g # Insert bibliography and index creation command. # Comment if you don't want! # # Substitute # # </book> # # with # # &index; # </book> # #/<\/book>/s/<\/book>/\&bibliography;\ #\&index;\ #<\/book>/ # Insert bibliography and index creation command. # Comment if you don't want! # # Substitute # # </article> # # with # # &index; # </article> # #/<\/article>/s/<\/article>/\&bibliography;\ #\&index;\ #<\/article>/ # Key combinations # # CTRL-X-Y s/\([^-]\)CTRL-\([^-. &<]*\)-\([^-. &,)<]*\)/\1\ <keycombo>\ <keycap>CTRL<\/keycap>\ <keycap>\2<\/keycap>\ <keycap>\3<\/keycap>\ <\/keycombo>\ <indexterm>\ <primary>CTRL_\2_\3<\/primary>\ <\/indexterm>\ /g # CTRL-X s/\([^-]\)CTRL-\([^-. &,)<]*\)/\1\ <keycombo>\ <keycap>CTRL<\/keycap>\ <keycap>\2<\/keycap>\ <\/keycombo>\ <indexterm>\ <primary>CTRL_\2<\/primary>\ <\/indexterm>\ /g # CTRL s/\([^-]\)CTRL\([ .,\t\r\n)]\)/\1\ <keycombo>\ <keycap>CTRL<\/keycap>\2\ <\/keycombo>\ <indexterm>\ <primary>CTRL<\/primary>\ <\/indexterm>\ /g s/CTRL_\([^-. &<]*\)_\([^-. &,)<]*\)/CTRL-\1-\2/g s/CTRL_\([^-. &<]*\)/CTRL-\1/g # ESC-X-Y s/\([^-]\)ESC-\([^-. &<]*\)-\([^-. &,)<]*\)/\1\ <keycombo>\ <keycap>ESC<\/keycap>\ <keycap>\2<\/keycap>\ <keycap>\3<\/keycap>\ <\/keycombo>\ <indexterm>\ <primary>ESC_\2_\3<\/primary>\ <\/indexterm>\ /g # ESC-X s/\([^-]\)ESC-\([^-. &,)<]*\)/\1\ <keycombo>\ <keycap>ESC<\/keycap>\ <keycap>\2<\/keycap>\ <\/keycombo>\ <indexterm>\ <primary>ESC_\2<\/primary>\ <\/indexterm>\ /g # ESC s/\([^-]\)ESC\([ .,\t\r\n)]\)/\1\ <keycombo>\ <keycap>ESC<\/keycap>\2\ <\/keycombo>\ <indexterm>\ <primary>ESC<\/primary>\ <\/indexterm>\ /g s/ESC_\([^-. &<]*\)_\([^-. &,)<]*\)/ESC-\1-\2/g s/ESC_\([^-. &<]*\)/ESC-\1/g # ALT-X-Y s/\([^-]\)ALT-\([^-. &<]*\)-\([^-. &,)<]*\)/\1\ <keycombo>\ <keycap>ALT<\/keycap>\ <keycap>\2<\/keycap>\ <keycap>\3<\/keycap>\ <\/keycombo>\ <indexterm>\ <primary>ALT_\2_\3<\/primary>\ <\/indexterm>\ /g # ALT-X s/\([^-]\)ALT-\([^-. &,)<]*\)/\1\ <keycombo>\ <keycap>ALT<\/keycap>\ <keycap>\2<\/keycap>\ <\/keycombo>\ <indexterm>\ <primary>ALT_\2<\/primary>\ <\/indexterm>\ /g # ALT s/\([^-]\)ALT\([ .,\t\r\n)]\)/\1\ <keycombo>\ <keycap>ALT<\/keycap>\2\ <\/keycombo>\ <indexterm>\ <primary>ALT<\/primary>\ <\/indexterm>\ /g s/ALT_\([^-. &<]*\)_\([^-. &,)<]*\)/ALT-\1-\2/g s/ALT_\([^-. &<]*\)/ALT-\1/g # Acronyms # PHP, GNU, EOF, Python, POSIX, GUI, LDP... s/\([ .\t\r\n]\)PHP\([ .\t\r\n]\)/\1<acronym>PHP<\/acronym>\2/g s/\([ .\t\r\n]\)GNU\([ .\t\r\n]\)/\1<acronym>GNU<\/acronym>\2/g s/\([ .\t\r\n]\)EOF\([ .\t\r\n]\)/\1<acronym>EOF<\/acronym>\2/g s/\([ .\t\r\n]\)Python\([ .\t\r\n]\)/\1<acronym>Python<\/acronym>\2/g s/\([ .\t\r\n]\)POSIX\([ .\t\r\n]\)/\1<acronym>POSIX<\/acronym>\2/g s/\([ .\t\r\n]\)GUI\([ .\t\r\n]\)/\1<acronym>GUI<\/acronym>\2/g s/\([ .\t\r\n]\)LDP\([ .\t\r\n]\)/\1<acronym>LDP<\/acronym>\2/g s/\([ .\t\r\n]\)IDE\([ .\t\r\n]\)/\1<acronym>IDE<\/acronym>\2/g s/\([ .\t\r\n]\)RPM\([ .\t\r\n]\)/\1<acronym>RPM<\/acronym>\2/g s/\([ .\t\r\n]\)PGP\([ .\t\r\n]\)/\1<acronym>PGP<\/acronym>\2/g s/\([ .\t\r\n]\)GPG\([ .\t\r\n]\)/\1<acronym>GPG<\/acronym>\2/g s/\([ .\t\r\n]\)ID\([ .\t\r\n]\)/\1<acronym>ID<\/acronym>\2/g s/\([ .\t\r\n]\)BW\([ .\t\r\n]\)/\1<acronym>BW<\/acronym>\2/g s/\([ .\t\r\n]\)ASCII\([ .\t\r\n]\)/\1<acronym>ASCII<\/acronym>\2/g s/\([ .\t\r\n]\)CPU\([ .\t\r\n]\)/\1<acronym>CPU<\/acronym>\2/g # Product names # UNIX, Linux, Acrobat, Windows... s/\([ .\t\r\n]\)UNIX\([ .\t\r\n]\)/\1<productname>UNIX<\/productname>\2/g s/\([ .\t\r\n]\)Linux\([ .\t\r\n]\)/\1<productname>Linux<\/productname>\2/g s/\([ .\t\r\n]\)Acrobat\([ .\t\r\n]\)/\1<productname>Acrobat<\/productname>\2/g s/\([ .\t\r\n]\)Windows\([ .\t\r\n]\)/\1<productname>Windows<\/productname>\2/g s/\([ .\t\r\n]\)Mandrake\([ .\t\r\n]\)/\1<productname>Mandrake<\/productname>\2/g s/\([ .\t\r\n]\)SuSE\([ .\t\r\n]\)/\1<productname>SuSE<\/productname>\2/g # Applications # TeX, LaTeX, Acrobat Reader, PHP-Nuke s/\([ .\t\r\n]\)TeX\([ .\t\r\n]\)/\1<application>TeX<\/application>\2/g s/\([ .\t\r\n]\)LaTeX\([ .\t\r\n]\)/\1<application>LaTeX<\/application>\2/g s/\([ .\t\r\n]\)Reader\([ .\t\r\n]\)/\1<application>Reader<\/application>\2/g s/\([ .\t\r\n]\)PHP-Nuke\([ .\t\r\n]\)/\1<application>PHP-Nuke<\/application>\2/g s/\([ .\t\r\n]\)Perl\([ .\t\r\n]\)/\1<application>Perl<\/application>\2/g s/\([ .\t\r\n]\)Java\([ .\t\r\n]\)/\1<application>Java<\/application>\2/g