# How to force RefTeX to parse the document for a specific word

One of the book which I am translating is using "Ruby" macros and Ruby makes all pre-processing for LaTeX.

For Example, there is a command inside the document such as:

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

which calls a Ruby script:

``````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
#      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
``````

I may make a reference to fig inside the document by using `\pageref{fig:soccer-ball}` but this is not handled by RefTeX. I have to write it by hand. But I want to complete it by running a command like `C-c )` in RefTeX. (or using helm-reftex or ivy-reftex)

there is no label for the figure that I can use. I wonder I may define a new RefTeX macro such that it will parse the document and find all mentions with `<% fig(" ") %>` and give me all instances of it.

• @Arash Asbati, Thank you and it is working. Although you could elaborate your answer a little bit how to generalize to other keywords. For example, I don't understand meaning `[a-z-]`. In the original post, I forgot to include second parenthesis. The original question should be ` <% fig("soccer-ball") %>` . Could you update the answer according to this. Jul 4 '19 at 21:25

RefTeX provides a variable for this purpose called `reftex-label-regexps`. You have to customize this variable with the appropriate regular expression which can look like this:
``````<%[[:space:]]*fig("\(?1:[a-z-]+\)"
Enter M-x customize-variable RET reftex-label-regexps RET, hit the `INS` button, add the regexp above and hit `Apply and Save`. In Emacs, it should look like this:
Customize the value of `reftex-label-menu-flags` if you want to see commented labels per default.