On Wed, Nov 07, 2007 at 09:06:52PM +0100, Andre Poenitz wrote:
> On Wed, Nov 07, 2007 at 09:29:38PM +0200, Martin Vermeer wrote:
> > 
> > Has anybody else noticed that the branches feature doesn't work inside
> > math and inside graphics?
> 
> Not me ;-)
> 
> > It would be especially nice to have it in the
> > "special" LaTeX strings inside XFig graphics. An in text phrases inside
> > math, like 
> > 
> >         / 0  if x > 0
> > f(x) = |
> >         \ 1  if x <= 0
> > 
> > where you may want to have "if" in a different language.
> > 
> > The attached does precisely that. It adds raw LaTeX commands \b<branchname> 
> > that are then available to the user. When enabled, they just pass through
> > their content, when disabled, they suppress it.
> 
> Nice.
> 
> > 
> > A demo is attached too. (You may have to tinker with the pathname of
> > branch.fig to get it showing on your system) 
> > 
> > - Martin
> > 
> 
> > Index: InsetBranch.cpp
> > ===================================================================
> > --- InsetBranch.cpp (revision 21475)
> > +++ InsetBranch.cpp (working copy)
> > @@ -22,6 +22,7 @@
> >  #include "FuncRequest.h"
> >  #include "FuncStatus.h"
> >  #include "gettext.h"
> > +#include "LaTeXFeatures.h"
> >  #include "Lexer.h"
> >  #include "OutputParams.h"
> >  
> > @@ -212,8 +213,10 @@
> >             std::find_if(branchlist.begin(), end,
> >                          BranchNamesEqual(params_.branch));
> >     if (it == end)
> > -           return false;
> > -   return it->getSelected();
> > +           selected_ = false;      
> > +   else
> > +           selected_ = it->getSelected();
> > +   return selected_;
> >  }
> >  
> >  
> > @@ -269,6 +272,12 @@
> >  
> >  void InsetBranch::validate(LaTeXFeatures & features) const
> >  {
> > +   string const name = to_utf8(params_.branch);
> > +   features.require(name);
> > +   if (selected_)
> > +           features.addPreambleSnippet("\\newcommand{\\b" + name + 
> > "}[1]{#1}");
> > +   else
> > +           features.addPreambleSnippet("\\newcommand{\\b" + name + 
> > "}[1]{}");
> >     InsetText::validate(features);
> >  }
> 
> Could you name the macros "\lyxbranch" + name or such?
> 
> Andre'

Yes, sure. But that's a lot of typing (you'll end up typing this
yourself, many times over, do you realize that?)

- Martin

Reply via email to