如何强制 RefTeX 解析文档中的特定单词

如何强制 RefTeX 解析文档中的特定单词

我正在翻译的一本书使用了“Ruby”宏,Ruby 对 LaTeX 进行了所有的预处理。

例如,文档里面有这样一个命令:

<% fig("soccer-ball") %>

调用 Ruby 脚本:

def fig(name,caption=nil,options={})   default_options = {
    'anonymous'=>'default',# true means figure has no figure number, but still gets labeled (which is, e.g., 
                           #      necessary for photo credits)
                           # default is false, except if caption is a null string, in which case it defaults to true
    'width'=>'narrow',     # 'native'=whatever the figure says it is, 'narrow'=52 mm, 'column'=76.5 mm,
                           #   'wide'=113 mm, 'fullpage'=171 mm
                           #   refers to graphic, not graphic plus caption (which is greater for sidecaption option)
    'sidecaption'=>false,
    'sidepos'=>'t',        # positioning of the side caption relative to the figure; can also be b, c
    'float'=>'default',    # defaults to false for narrow, true for wide or fullpage (because I couldn't get odd-even to work reliably for those if not floating)
    'floatpos'=>'h',       # standard latex positioning parameter for floating figures
    'narrowfigwidecaption'=>false, # currently only supported with float and !anonymous
    'suffix'=>'',          # for use when a figure is used in more than one place, and we need to make the label unique;
                           #   typically 'suffix'=>'2'; don't need this option on the first fig, only the second
    'text'=>nil,           # if it exists, puts the text in the figure rather than a graphic (name is still required for labeling)
                           #      see macros \starttextfig and \finishtextfig
                           # For an example of how to do this, see SN ch. 3, "Gory details of the proof..."
                           # Tables and align* don't work in text, nor does \\, but paragraph breaks work;
                           # may be able to get around this with minipage.
    'title'=>nil,          # for use with 'text', goes above the text
    'raw'=>false,          # used for anonymous inline figures, e.g., check marks; generates a raw call to includegraphics
    'textbox'=>false       # marginbox(), as used in Fund.; won't work in other books, which don't have the macros in their cls files
    # not yet implemeted: 
    #    translated=false
    #      or just have the script autodetect whether a translated version exists!
    #    toc=false
    #      figure is to be used in table of contents
    #      see macros \figureintoc, \figureintocnoresize
    #    midtoc=false
    #      figure in toc is to be used in the middle of a chapter (only allowed with toc=true)
    #      see macro figureintocscootx
    #    scootdown=0
    #      distance by which to scoot it down (only allowed with toc=true)
    #      see macro figureintocscooty
    #    gray=false
    #      automagically add a gray background
    #    gray2=false
    #      automagically add a gray background if it's 2-column
    #    resize=true
    #      see macros \fignoresize, \inlinefignocaptionnoresize   }   unless caption.nil? then caption.gsub!(/\A\s+/,'') end # blank lines on the front make latex freak out   if caption=='' then caption=nil end   default_options.each { 
    |option,default|
    if options[option]==nil then
      options[option]=default
    end   }   width=options['width']   if options['narrowfigwidecaption'] then
    options['width']='wide'; options['sidecaption']=true; options['float']=false; options['anonymous']=false   end

  # Generate fig_widths. To regenerate these, change false to true below, and then follow   # directions in ~/Documents/writing/books/physics/data/README. This data file is used by problems book.   if false && width!='narrow' then
    File.open('/home/bcrowell/fig_widths','a') { |f|
      f.print "\"#{name}\":\"#{width}\",\n"
    }   end

  if options['float']=='default' then
    options['float']=(width=='wide' or width=='fullpage')   end   has_caption = !(caption.nil?)   if options['anonymous']=='default' then
    options['anonymous']=!has_caption   end   dir = find_directory_where_figure_is(name)   if dir.nil? && options['text'].nil? then fatal_error("figure #{name} not found in
#{dir()}/figs or #{shared_figs()}, ch=#{$ch}") end   #------------------------------------------------------------   if is_print then fig_print(name,caption,options,dir) end  
#------------------------------------------------------------   if is_web then process_fig_web(name,caption,options) end end

我可以使用在文档中引用 fig \pageref{fig:soccer-ball},但这不是 RefTeX 处理的。我必须手写。但我想通过运行类似C-c )RefTeX 中的命令来完成它。(或使用 helm-reftex 或 ivy-reftex)

没有我可以使用的图形标签。我想知道我是否可以定义一个新的 RefTeX 宏,以便它可以解析文档并找到所有提及<% fig(" ") %>并向我提供它的所有实例。

答案1

RefTeX 为此提供了一个名为 的变量reftex-label-regexps。您必须使用适当的正则表达式自定义此变量,如下所示:

<%[[:space:]]*fig("\(?1:[a-z-]+\)"

输入M-x customize-variable RET reftex-label-regexps RET,点击INS按钮,添加上面的正则表达式并点击Apply and Save。在 Emacs 中,它应该如下所示:

在此处输入图片描述

现在重新启动 Emacs 并打开 .tex 文件。点击 时C-c ) RET SPACE,您应该会看到一个空的 RefTeX 缓冲区。点击%查看注释标签。对我来说,它看起来像这样:

在此处输入图片描述

reftex-label-menu-flags如果您想默认查看注释标签,请自定义值。

相关内容