Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}}
share|improve this question
    
Have a look at this topic: Name of current section/figure –  Marco Daniel Aug 13 '11 at 10:41
    
I think this question is too localised... –  Seamus Aug 13 '11 at 13:24

2 Answers 2

up vote 3 down vote accepted

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}}
    
share|improve this answer
    
the do not the same! –  Herbert Aug 13 '11 at 10:43
    
@Herbert: Oh I see. I should check up my eyes. :-) –  xport Aug 13 '11 at 10:49
1  
with fancyref it is \newcommand\tabpage[1]{Table~\vref{#1}} –  Herbert Aug 13 '11 at 13:15
    
+1 I see. Thanks. –  xport Aug 13 '11 at 14:19

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.