On 12/19/18 11:18 AM, Bert Lloyd wrote:
> Dear LyX Users,
>
> When writing problem sets, I create a Solutions branch so that I can
> maintain just a single LyX file. I like to give students .tex and .lyx
> files so they can type up their solutions.
>
> Creating a .tex file without the content of the Solutions branch is
> very easy - I just toggle off the Solutions branch and export to .tex
> in the usual way.
>
> Is there a similar way to "export" (or just save-as) a .lyx file
> without deactivated branches? At the moment, my workaround is to
> export to tex and then import tex to lyx.

There *might* be a way to do this with the inset-forall LFUN, but I
wouldn't know for sure. Depending upon how many there are, you could try
using the outliner, sorting by branch name, and deleting manually.
Another option, which is always available, is to write some kind of perl
or python script to remove the unwanted branches from the LyX file
directly. Something like (in perl):

$inset_count = 0;
$in_branch = 0;
while (<>) {
    if (m{^//begin_inset Branch Solution}) {
        $in_branch = 1;
        $inset_count = 1;
    } elsif ($in_branch) {
        if (m{^\\begin_inset}) { $inset_count++; }
        elsif (m{\\end_inset}) { $inset_count--; }
        if ($inset_count == 0) { $in_branch = 0; }
    } else {
        print;
    }
}

Not tested!! (Usage: perl thatfile.pl < oldfile.lyx >newfile.lyx)

It's one nice thing about LyX files being just flat text files that you
can do this kind of thing so easily.

Riki


Reply via email to