Md Abdus Samad, PhD
  • About
    • News
    • Contact
  • Publications
  • LaTeX
  • My Blog
  • Guidance
    • Top Global Scholarships
    • University Portal
  • 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
  • Other Sites
    • Scholar’s Note

On this page

  • Document Comparison and Track Changes
    • Compare Two .tex Files with latexdiff
    • Hide Deleted Text and Highlight Additions
  • Table Design and Layout
    • Color Entire Table
    • Adjust Table Spacing
    • Multi-Column Table Syntax
    • Multi-Row Table Syntax
    • Resize Table to Fit Page Width
  • Algorithm Formatting
    • Algorithm Autoref Support
    • Sub-Step Numbering in Algorithms
    • Split Algorithm Across Pages
  • Hyperlink Styling
    • Custom Link Colors
  • Citations and Bibliography
    • Force Numbered Style
    • Use (1) Style Instead of [1]
    • Back to Square Brackets
    • Show Citation Keys for Debugging
  • Compilation and Debugging
    • Show Loaded Packages
    • Delete Aux Files (Bash)
    • Full Compile Sequence (with BibTeX)
  • Git Integration with Overleaf
    • Get Overleaf Project URL
    • Clone Overleaf Project
    • Push Local Changes to Overleaf
    • Pull Before Push to Avoid Conflict
    • Command Summary
  • Opening PDFs from Git Bash on Windows
    • Navigate to Directory
    • Open PDF in Default Viewer
    • Automate Compile and Open
  • Word Counting in LaTeX
  • Creating LaTeX Tables with Merged Headers
    • Optional Customizations
  • TabularX Column Spacing Issues
    • Why This Happens
    • Solutions
  • Creating Sequential Dummy Figures in LaTeX with TikZ
    • What this code does
  • TeXstudio Search and Replace with Regex
    • Remove Asterisks from Section Headers
    • Add Asterisks to Section Headers (Reverse Operation)
  • VS Code Keyboard Shortcuts for LaTeX
    • Essential Shortcuts by Category
  • Quick Reference Table
    • Document Comparison
    • Table Operations
    • Cross-References & Citations
    • Compilation & Debugging
    • Version Control with Overleaf (Git)

LaTeX Reference Guide

Essential Commands and Tips for Academic Writing

Author

Dr. Md Abdus Samad

Published

May 30, 2025

Document Comparison and Track Changes

Compare Two .tex Files with latexdiff

VS Code: Open integrated terminal with Ctrl+ ` (backtick)

latexdiff --append-context2cmd="abstract" old.tex new.tex > diff.tex

Generates diff.tex with additions underlined in red.

Hide Deleted Text and Highlight Additions

\providecommand{\DIFdel}[1]{}
\providecommand{\DIFadd}[1]{{\color{red}\uline{#1}}}

Table Design and Layout

Color Entire Table

{\color{red}
\begin{tabular}{cc}
a & b \\
1 & 2 \\
\end{tabular}}

Adjust Table Spacing

\setlength{\tabcolsep}{20pt}
\renewcommand{\arraystretch}{1.5}

Multi-Column Table Syntax

\multicolumn{2}{c}{Merged Cell}

Multi-Row Table Syntax

\usepackage{multirow}
\multirow{2}{*}{Merged Row}

Resize Table to Fit Page Width

\resizebox{\linewidth}{!}{%
\begin{tabular}...\end{tabular}}

Algorithm Formatting

Algorithm Autoref Support

\newcommand{\algorithmautorefname}{Algorithm}

Sub-Step Numbering in Algorithms

\usepackage{algorithm,algpseudocode}
\newcounter{algsubstate}
\renewcommand{\thealgsubstate}{\alph{algsubstate}}
\newenvironment{algsubstates}{
\setcounter{algsubstate}{0}
\renewcommand{\State}{
\stepcounter{algsubstate}
\Statex {\footnotesize\thealgsubstate:}\space}}{}

Split Algorithm Across Pages

\usepackage{algorithm, algcompatible}
\algstore{blockname}
...
\algrestore{blockname}

Hyperlink Styling

Custom Link Colors

\usepackage{hyperref}
\hypersetup{
colorlinks=true,
linkcolor=blue,
filecolor=blue,
urlcolor=blue,
allcolors=blue}
\urlstyle{same}

Citations and Bibliography

Force Numbered Style

\setcitestyle{numbers}

Use (1) Style Instead of [1]

\usepackage[numbers,round]{natbib}
\bibliographystyle{vancouver}

Back to Square Brackets

\usepackage[sort,numbers]{natbib}
\setcitestyle{square}

Show Citation Keys for Debugging

\usepackage{showlabels}
\renewcommand{\showlabelfont}{\small\color{blue}}
\showlabels[\small\color{gray}]{cite}
\showlabels[\small\color{red}]{bibitem}

Compilation and Debugging

Show Loaded Packages

\listfiles

Delete Aux Files (Bash)

VS Code: Open integrated terminal with Ctrl+ ` (backtick)

rm -f *.aux *.log *.toc *.out *.lof *.lot *.fls *.fdb_latexmk *.synctex.gz *.nav *.snm *.bbl *.blg *.vrb *.xdv

Full Compile Sequence (with BibTeX)

VS Code: Open integrated terminal with Ctrl+ ` (backtick) or use LaTeX Workshop extension

latexmk -pdf main.tex
# or manual:
pdflatex main.tex 
bibtex main
pdflatex main.tex
pdflatex main.tex

Git Integration with Overleaf

TipGetting Started

In Overleaf: Menu → Git → Enable Git

VS Code: Open integrated terminal with Ctrl+ (backtick) or use Source Control panel (Ctrl+Shift+G`)

Get Overleaf Project URL

If you already have a cloned Overleaf project and want to get the web URL:

VS Code: Open integrated terminal with Ctrl+ ` (backtick)

# Copy Overleaf web URL to clipboard
git remote get-url origin | sed 's|https://git@git.overleaf.com/|https://www.overleaf.com/project/|' | clip

This converts the git URL (https://git@git.overleaf.com/project_ID) to the proper web URL (https://www.overleaf.com/project/project_ID) and copies it to your clipboard.

Clone Overleaf Project

VS Code Command: Use Command Palette (Ctrl+Shift+P) → “Git: Clone”

Copy URL like: https://git.overleaf.com/project-id

cd ~/Documents
git clone https://git.overleaf.com/project-id
cd project-id

Push Local Changes to Overleaf

VS Code: - Open Source Control panel (Ctrl+Shift+G) - Stage changes, add commit message, click “Commit and Push” - Or use integrated terminal:

git add .
git commit -m "Update"
git push

Pull Before Push to Avoid Conflict

VS Code: Command Palette (Ctrl+Shift+P) → “Git: Pull (Rebase)”

git pull --rebase

Command Summary

Command Description VS Code Shortcut
git pull origin master Pull changes from Overleaf (remote: origin, branch: master) Ctrl+Shift+P → “Git: Pull”
git push origin master Push your local changes to Overleaf Ctrl+Shift+P → “Git: Push”
git pull overleaf master Same as above, but only if your remote is named overleaf Ctrl+Shift+P → “Git: Pull”

Opening PDFs from Git Bash on Windows

Navigate to Directory

cd /c/Users/YourName/Documents/latex-project

Open PDF in Default Viewer

start "" "main.pdf"
# or
explorer.exe "main.pdf"

Automate Compile and Open

VS Code: Open integrated terminal with Ctrl+ ` (backtick)

pdflatex main.tex && start "" "main.pdf"

Word Counting in LaTeX

VS Code: Open integrated terminal with Ctrl+ ` (backtick)

Use texcount for accurate word count:

texcount yourfile.tex
texcount -sum yourfile.tex
texcount -inc yourfile.tex
texcount -1 yourfile.tex
texcount -brief yourfile.tex
texcount -inc -sum -total main.tex

Creating LaTeX Tables with Merged Headers

NoteRequirements
  • Columns 1 and 2: vertical merge (2 rows)
  • Columns 3–5: under “Group Header” merged in first row, subheaders in second row
  • Column 6: vertical merge (2 rows)

Optional Customizations

  • Use booktabs for horizontal lines
  • Use tabularx with \textwidth for dynamic width
  • Center-align all columns
  • Add sample data rows
  • Include \caption{} and \label{}
  • Add colored headers (requires xcolor)
  • Ensure compilation-ready for Overleaf/TeXstudio

TabularX Column Spacing Issues

WarningProblem

Reducing column spacing with \setlength{\tabcolsep}{4pt} may lead to inconsistent column widths.

Why This Happens

  • Automatic Column Stretching: tabularx distributes remaining width among X columns proportionally
  • Reduced Padding: Smaller \tabcolsep makes differences more noticeable
  • Multiple X Columns: Algorithm may leave fractional rounding errors
  • Complex Tables: Multirow/multicolumn cells exacerbate uneven widths

Solutions

1. Use Proportional X Columns

\begin{tabularx}{\textwidth}{|>{\hsize=0.5\hsize}X|>{\hsize=1\hsize}X|c|}

2. Consider tabular* for Precise Control

\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}|l|l|l|}

3. Use Fixed-Width Columns

p{width}
TipPro Tips
  • Combine reduced \tabcolsep with \arraystretch for balanced spacing
  • Always test with multiple rows and different content lengths
  • For highly complex tables, consider splitting into smaller subtables

Creating Sequential Dummy Figures in LaTeX with TikZ

Sometimes you need placeholder figures while drafting. Here is how to generate 20 numbered dummy figures automatically:

\documentclass{article}
\usepackage{tikz}

\begin{document}

\section*{Sequential Dummy Figures with TikZ}

% Define a command to create a numbered dummy image
\newcommand{\numberedimage}[1]{%
  \begin{figure}[h!]
    \centering
    \begin{tikzpicture}
      \draw[fill=gray!30] (0,0) rectangle (4,3); % gray rectangle
      \node at (2,1.5) {\Huge Image #1};         % centered label
    \end{tikzpicture}
    \caption{Dummy figure #1}
  \end{figure}
}

% Generate 20 dummy figures
\numberedimage{1}
\numberedimage{2}
\numberedimage{3}
% ...continue to 20

\end{document}

What this code does

  • Defines a custom command \numberedimage{n}
  • Each dummy figure is a gray rectangle with “Image n” written inside
  • Figures are numbered 1 through 20, each with its own caption
NoteUse Cases
  • Testing figure layouts
  • Reserving space for future graphics
  • Creating mockups in academic papers

TeXstudio Search and Replace with Regex

Remove Asterisks from Section Headers

VS Code: Open Find and Replace with Ctrl+H

TeXstudio: Use Find & Replace with Ctrl+H → Enable Regular Expressions

NoteMethod 1: Standard Syntax (Try This First)

Search Pattern:

\\((?:sub){0,2})section\*\{([^}]+)\}

Replace Pattern:

\\\1section{\2}
WarningMethod 2: Escaped Parentheses (If Method 1 Doesn’t Work)

Search Pattern:

\\\((?:sub){0,2}\)section\*\{([^}]+)\}

Replace Pattern:

\\\1section{\2}

Add Asterisks to Section Headers (Reverse Operation)

VS Code: Open Find and Replace with Ctrl+H → Enable Regex mode (Alt+R)

TeXstudio: Use Find & Replace with Ctrl+H → Enable Regular Expressions

NoteMethod 1: Standard Syntax (Try This First)

Search Pattern:

\\((?:sub){0,2})section\{([^}]+)\}

Replace Pattern:

\\\1section*{\2}
WarningMethod 2: Escaped Parentheses (If Method 1 Doesn’t Work)

Search Pattern:

\\\((?:sub){0,2}\)section\{([^}]+)\}

Replace Pattern:

\\\1section*{\2}

VS Code Keyboard Shortcuts for LaTeX

Essential Shortcuts by Category

Editing & Navigation

Shortcut Action
Ctrl+P Quick Open File
Ctrl+G Go to Line
Ctrl+/ Comment Line / Toggle Comments
Ctrl+D Multi-cursor Selection (select next occurrence)
Ctrl+Shift+I Format Document

Search & Replace

Shortcut Action
Ctrl+F Find
Ctrl+H Find and Replace
Alt+R Toggle Regex Mode in Find/Replace

Version Control & Terminal

Shortcut Action
Ctrl+Shift+G Open Source Control (Git) Panel
Ctrl+ ` (backtick) Open Integrated Terminal

Command & Feature Access

Shortcut Action
Ctrl+Shift+P Open Command Palette
Ctrl+Shift+V Toggle Markdown Preview
Ctrl+K Ctrl+0 Fold All
Ctrl+K Ctrl+J Unfold All

Quick Reference Table

Document Comparison

Command Purpose
latexdiff old.tex new.tex > diff.tex Compare two LaTeX files

Table Operations

Command Purpose
\multicolumn{2}{c}{Text} Merge columns in tables
\multirow{2}{*}{Text} Merge rows in tables
\resizebox{\linewidth}{!}{...} Fit table to page width

Cross-References & Citations

Command Purpose
\algorithmautorefname Enable autoref support for algorithms
\setcitestyle{numbers} Use numbered citation style
\hypersetup{colorlinks=true} Enable colored hyperlinks

Compilation & Debugging

Command What It Does
latexmk -pdf main.tex ✓ Recommended – Single command, handles everything (PDF output)
pdflatex main.tex && bibtex main && pdflatex main.tex x2 Manual sequence for fine control or debugging
texcount -inc -sum main.tex Count words including external files + show summary
rm -f *.aux *.log *.toc *.out *.lof *.lot *.fls *.fdb_latexmk *.synctex.gz *.nav *.snm *.bbl *.blg *.vrb *.xdv Remove ALL temporary files and caches

Access via: Terminal (Ctrl+ `)


Version Control with Overleaf (Git)

TipBest Practice: Pull → Modify → Commit → Push

Always pull before starting work to avoid conflicts!

Task VS Code UI Terminal Command
Pull changes Ctrl+Shift+G → ··· → “Pull (Rebase)” git pull --rebase
Stage changes Ctrl+Shift+G → Click + icon git add .
Commit Enter message → Ctrl+Enter git commit -m "message"
Push to Overleaf Ctrl+Shift+G → ··· → “Push” git push

Terminal access: Ctrl+ ` (backtick)

 

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