2

I was searching around my editor and found some templates that I never used before and I was just wondering exactly what do they mean and do. Someone can edit the title is you have a better suggestion.

%%Definitions for Figure-References
\newcommand{\fig}[1]{(figure \ref{#1})}
\newcommand{\FIG}[1]{figure \ref{#1}}

%%Definitions for Table-References
\newcommand{\tab}[1]{(table \ref{#1})}
\newcommand{\TAB}[1]{table \ref{#1}}

%%Definitions for Page-References
\newcommand{\page}[1]{(page \pageref{#1})}
\newcommand{\PAGE}[1]{page \pageref{#1}}

%%Definitions for Code
\newcommand{\precode}[1]{\textbf{\footnotesize #1}}
\newcommand{\code}[1]{\texttt{\footnotesize #1}}
Stefan Kottwitz
  • 231,401
night owl
  • 7,593

2 Answers2

4

they are not correct. Should be:

%%Definitions for Figure-References
\newcommand{\fig}[1]{(Figure~\ref{#1})}
\newcommand{\FIG}[1]{Figure~\ref{#1}}

%%Definitions for Table-References
\newcommand{\tab}[1]{(Table~\ref{#1})}
\newcommand{\TAB}[1]{Table~\ref{#1}}

%%Definitions for Page-References
\newcommand{\page}[1]{(page~\pageref{#1})}
\newcommand{\PAGE}[1]{page~\pageref{#1}}

%%Definitions for Code
\newcommand{\precode}[1]{\textbf{\footnotesize #1}}
\newcommand{\code}[1]{\texttt{\footnotesize #1}}

The ~ dosn't allow a line break between the word and the ref. They all save some keystrokes, you can say as seen in \fig{fig_label}. Same for table and page. The lowercase variants put this reference into (...) The last two are only abbreviations for typesetting precode in bold font and code in typewriter font, both in footnote size

3

They are just macros to make cross-references and code snippet markups. Defining such macros is a good practice because you can modify the macros definition in one place and the changes will take effect throughout the document.

The following code shows you what they are for. You will get the idea!

\documentclass{article}

%%Definitions for Figure-References
\newcommand\fig[1]{figure~\ref{#1}}


%%Definitions for Table-References
\newcommand\tab[1]{table~\ref{#1}}


%%Definitions for Page-References
\newcommand\page[1]{page~\pageref{#1}}


%%Definitions for Code
\newcommand\precode[1]{\textbf{\footnotesize #1}}
\newcommand\code[1]{\texttt{\footnotesize #1}}

\usepackage{lipsum}
\usepackage[demo]{graphicx}
\usepackage[colorlinks]{hyperref}

\begin{document}
\section{Introduction}\label{sec:Inroduction}
\lipsum[1]
\begin{figure}[hbtp]
\centering
\includegraphics[width=0.5\linewidth]{cat}
\caption{This is a cat.}
\label{fig:cat}
\end{figure}
\lipsum[2-10]
For the detail see \fig{fig:cat} on \page{fig:cat}.

\begin{table}[hbtp]
\centering
\begin{tabular}{|c|c|}\hline
a & b \\\hline
c & d \\\hline
\end{tabular}
\caption{This is a table, not a desk!}
\label{tab:Schedule}
\end{table}
\lipsum[11-20]
See \tab{tab:Schedule} on \page{tab:Schedule} for the detailed explanation.

You can type \code{var a = b - c;} in the source editor.
\end{document}

NOTE:

  1. You don't need to overload macro by capitalization if they do the same thing. Defining one of {\tab, \TAB, \TaB, etc} is enough.
  2. For printed document, we usually print both Figure/Table references together with page numbers. Therefore, you can combine Figure-Page and Table-Page as follows.

    \newcommand\tabpage[1]{Table~\ref{#1} on page~\pageref{#1}}
    

    or

    \newcommand\figpage[1]{Figure~\ref{#1} on page~\pageref{#1}}
    
Display Name
  • 46,933