Md Abdus Samad
  • About
    • News
    • Contact
  • Publications
  • Top Global Scholarships
  • University Information
  • LaTeX
  • Miscellaneous
    • List of Publishers
    • Journal Templates
    • Verifying Journal Indexing
    • Reference, Image Quality, and Detexify
    • Author Services by Major Publishers
    • Document Conversion and Figure Tools
    • Manuscript Anonymization
    • Switching Elsevier LaTeX Templates
    • DOCX to LaTeX Convert
    • LaTeX Reference and Label Management
    • Latex Reference Converter
    • Sequential Section Labels
    • Open Access Journals having Discount Policy
    • Overleaf git sync issues
    • Latexdiff Configuration Guide
    • Open source tools
    • Windows shortcuts & commands
    • Mathpix PDF to Word

On this page

  • Why This Matters
  • Step 1: Setting Up Regex Search in Overleaf
  • Step 2: Converting Figure References
    • Search Pattern
    • Replace Pattern
  • Step 3: Converting Table References
    • Search Pattern
    • Replace Pattern
  • Step 4: Advanced - Case-Insensitive Matching
    • For Figures (case-insensitive)
    • For Tables (case-insensitive)
  • Step 5: One-Pass Solution
    • Search Pattern
    • Replace Pattern
  • Step 6: Handling Edge Cases
    • Preserving Sentence Capitalization
    • Handling Plural Forms
  • Pro Tips for Success
  • Next Steps

LaTeX Reference Converter

Transform Manual Figure and Table References into Proper LaTeX Citations Using Regex in Overleaf

Author

Dr. Md Abdus Samad

Published

May 30, 2025

Why This Matters

NoteIntroduction

When writing academic papers, reports, or theses in LaTeX, you often reference figures and tables throughout your document. Converting manual references like “figure 1” or “table 2” into proper LaTeX references (\ref{fig:1}, \ref{tab:2}) ensures:

  • Automatic numbering: LaTeX handles figure/table numbering automatically
  • Clickable links: References become clickable in PDFs
  • Easy maintenance: No need to renumber when adding/removing figures
  • Professional formatting: Consistent with LaTeX best practices

This tutorial will save you hours of manual editing using Overleaf’s powerful regex search and replace feature.


Step 1: Setting Up Regex Search in Overleaf

  1. Open your LaTeX project in Overleaf
  2. Press Ctrl + F (Windows/Linux) or Cmd + F (Mac) to open the Find/Replace panel
  3. Click the .* button to enable regex search mode
  4. Ensure the search panel shows “Regular expressions enabled”
WarningImportant Tips

Always backup your document before running global replacements. Use Overleaf’s version history or download a copy of your project.


Step 2: Converting Figure References

Let us convert all instances of “figure X” to proper LaTeX references:

Search Pattern

figure\s+(\d+)
NotePattern Breakdown
  • figure - matches the literal word “figure”
  • \s+ - matches one or more whitespace characters (spaces, tabs)
  • (\d+) - captures one or more digits in group 1

Replace Pattern

\ref{fig:\1}

Click Replace All to apply the changes.

TipExamples

Before: “As shown in figure 3, the results indicate…” After: “As shown in Figure~\ref{fig:3}, the results indicate…”

Before: “Figure 12 demonstrates the effectiveness of…” After: “Figure~\ref{fig:12} demonstrates the effectiveness of…”


Step 3: Converting Table References

Now let us handle table references using the same approach:

Search Pattern

table\s+(\d+)

Replace Pattern

\ref{tab:\1}

Click Replace All to convert all table references.

TipExample

Before: “The data in table 5 shows significant improvement…” After: “The data in \ref{tab:5} shows significant improvement…”


Step 4: Advanced - Case-Insensitive Matching

To handle variations like “Figure”, “FIGURE”, “Table”, “TABLE”, use these enhanced patterns:

For Figures (case-insensitive)

(?i)figure\s+(\d+)

For Tables (case-insensitive)

(?i)table\s+(\d+)
NotePattern Addition
  • (?i) - enables case-insensitive matching for the entire pattern

Step 5: One-Pass Solution

NoteAlternative Approach

If you prefer to handle both figures and tables in a single operation:

Search Pattern

(?i)(figure|table)\s+(\d+)

Replace Pattern

\ref{\L\1:\2}
NoteAdvanced Pattern Breakdown
  • (figure|table) - captures either “figure” or “table” in group 1
  • \L\1 - converts the captured word to lowercase
  • \2 - inserts the captured number
TipExample

Before: “Figure 3 and Table 7 show…” After: “\ref{figure:3} and \ref{table:7} show…”

Note: This produces \ref{figure:3} instead of \ref{fig:3}. For standard LaTeX conventions, it is recommended to use separate passes as shown in steps 2-3.


Step 6: Handling Edge Cases

Preserving Sentence Capitalization

For references at the beginning of sentences, you might want to preserve capitalization:

Search:

^Figure\s+(\d+)

Replace:

Figure~\ref{fig:\1}
TipExample

Before: “Figure 2 illustrates the concept.” After: “Figure~\ref{fig:2} illustrates the concept.”

Handling Plural Forms

Search:

figures\s+(\d+)\s+and\s+(\d+)

Replace:

\ref{fig:\1} and \ref{fig:\2}

Pro Tips for Success

  • Test first: Try your regex pattern on a small section before applying to the entire document
  • Use Find Next: Use “Find” to preview matches before clicking “Replace All”
  • Check your labels: Ensure your figure and table environments have corresponding \label{fig:X} and \label{tab:X}
  • Consider spacing: Use ~ (non-breaking space) before references to prevent line breaks: Figure~\ref{fig:1}
  • Compile often: Run your LaTeX document after each major change to catch any issues early
  • Version control: Save versions of your work regularly in Overleaf’s history

Next Steps

After converting your references, remember to:

  1. Compile your document to ensure all references work correctly
  2. Check for any missed references that might have unusual formatting
  3. Add appropriate labels to any figures/tables that do not have them
  4. Consider using cleveref package for even more sophisticated referencing
% Add to your preamble for enhanced referencing
\usepackage{cleveref}

% Then use \cref{fig:1} instead of Figure~\ref{fig:1}

NoteSummary

Using regex search and replace in Overleaf transforms the tedious task of converting manual references into an efficient, automated process. This technique not only saves time but also ensures consistency and professionalism in your LaTeX documents. Master these patterns, and you will be able to quickly convert any academic document to use proper LaTeX referencing conventions.

 

© 2025 Dr. Md Abdus Samad. All rights reserved.