Please note:The SCons wiki is in read-only mode due to ongoing spam/DoS issues. Also, new account creation is currently disabled. We are looking into alternative wiki hosts.

Teaching PDF to understand .lyx files

I have not had the time (nor the knowledge) to convert this to an extension. Feel free to do so and edit this page!

The technique with add_src_builder could also help in other cases, sometimes asked at the mailing list. License: public domain.

Notice two things:

  1. The path to the tex files must be available at creation time of Environment, otherwise the default PDF builder claims that he does not understand how to build pdf from tex. There should be a better error message.
  2. add_src_builder does not work like env.PDF.add_src_builder . See below how it's done.

Usage

   1 env = Environment(ENV=dict(PATH='/usr/texbin:/bin:/usr/bin'))  
   2 if env['PLATFORM'] == "darwin":
   3     env.PrependENVPath( 'PATH', '/Applications/LyX.app/Contents/MacOS')
   4 
   5 pdf = env.PDF(source='report.lyx')

Implementation

   1 import SCons.Script
   2 def namelyxtarget(target, source, env):
   3     '''The name of the output tex file is the same as the input.'''
   4     assert len(source) == 1, 'Lyx is single_srouce only.'
   5     s = str(source[0])
   6     if s.endswith('.lyx'): 
   7         target[0] = s[0:-4] +'.tex'
   8     return target, source
   9        
  10 env.lyx = SCons.Script.Builder( action = 'lyx --export pdflatex $SOURCE', 
  11                                 suffix = '.tex', src_suffix='.lyx', 
  12                                 single_source=True, # file by file
  13                                 emitter = namelyxtarget )
  14 env.Append(BUILDERS = {'Lyx' : env.lyx})
  15  
  16 # Teach PDF to understand lyx
  17 env['BUILDERS']['PDF'].add_src_builder(env.lyx)

LyxBuilder (last edited 2011-02-28 12:33:54 by ip-95-222-195-154)