Often proceedings give authors sample .tex files to demonstrate how a
paper should be formatted. I generally want to make my preamble as
close as possible the sample. Usually I can trick LyX into generating
something pretty close to the sample preamble, but before submitting
manually tweak the .tex file to remove unneeded options etc. For lolz,
I spend a couple of days in LyX getting the pagination just right,
then discover that the pagination changes once I manually fix the
preabmle in the .tex file. Additionally, it is much faster to
cut-and-paste a preamble than it is to hunt round in LyX to find all
the options.  For these reasons, I use a wrapper script around
pdflatex like the one below.

However I was wondering if this sounds like a good feature for LyX itself?

My suggested implementation would be that you can set an option in
Document Settings->LaTeX Preamble like "edit whole preamble". When
this option is set LyX copies the whole preamble into the text box,
and allows the user to edit it as normal text.

-- pdflatex --
#!/bin/bash
THIS_SCRIPT="$0"
echo AT "$@"
echo AT "$@" 1>&2
echo AT "$@"  > /tmp/AT

echo "$*" | grep -o '\b[^ ]*.tex' | head -n1 | (
        read texfile
        echo TEXFILE $texfile
        mv $texfile $texfile.orig
        grep '^%PREAM ' $texfile.orig | sed 's/^%PREAM //' > $texfile
        "$THIS_SCRIPT".strip_preamble.py < $texfile.orig >> $texfile
        /usr/bin/pdflatex "$@"
        rm $texfile.mod
        mv $texfile $texfile.mod
        mv $texfile.orig $texfile
)

-- pdflatex.strip_preamble.py --
#!/usr/bin/env python
import sys

preamble=True;
for line in sys.stdin:
        if preamble:
                if line == '\\begin{document}\n':
                        preamble=False
                        print line,
        else:
                        print line,

-- 
John C. McCabe-Dansted
PhD Student
University of Western Australia

Reply via email to