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 have defined the following

\providecommand*{\lstnumberautorefname}{line}

and within my text

\begin{lstlisting} 
            |\label{sdd_1}|<sqlCallStatistics>YES</sqlCallStatistics>
\end{lstlisting}

When I now use in my text

xxx. \autoref{sdd_1} 

then I receive the following output :

xxxx. line 1 

instead of (what I had expected)

xxxx. Line 1
share|improve this question
    
Why would you expect an upper case "L" when defining \lstnumberautorefname with a lower case "l"? –  Gonzalo Medina Nov 8 '11 at 19:56
    
@GonzaloMedina: True, I guess "capitalization" should refer to "auto capitalization". –  Werner Nov 8 '11 at 20:00
    
@Werner: As far as I know, \autoref doesn't do "auto capitalization". –  Gonzalo Medina Nov 8 '11 at 20:03
    
Yes, that's true. You have to manually alter it to accommodate this, which almost defeats the purpose of "auto"-\ref-ing it. –  Werner Nov 8 '11 at 20:05
    
Well, this may be a rather awkward solution, but would it not be possible to create an \Autoref macro, which will locally redefine all of the \somethingautorefnames to a capitalized version? (Or, alternatively, just the one for the autoref target?) –  einpoklum Jan 6 '12 at 9:25

3 Answers 3

\autoref doesn't do automatic capitalization, as the following example illustrates:

\documentclass{article}
\usepackage{listings}
\usepackage{hyperref}

\providecommand*{\lstnumberautorefname}{line}

\begin{document}

\section{Test}\label{sec:test}
\autoref{sec:test} and a period before the reference. \autoref{sec:test}
\begin{lstlisting} [escapeinside=||,numbers=left]
      <sqlCallStatistics>YES</sqlCallStatistics>|\label{sdd_1}|
\end{lstlisting}

\autoref{sdd_1}  and a period before the reference. \autoref{sdd_1}

\end{document}

You could use the cleveref package to have \cref (for lower case) and \Cref (for upper case):

\documentclass{article}
\usepackage{listings}
\usepackage{cleveref}

\begin{document}

\begin{lstlisting} [escapeinside=||,numbers=left]
      <sqlCallStatistics>YES</sqlCallStatistics>|\label{sdd_1}|
\end{lstlisting}

\cref{sdd_1}  and a period before the reference. \Cref{sdd_1}

\end{document}
share|improve this answer

Here is a way to get \Autoref from hyperref package. Heiko Oberdiek (the maintainer of the package) will provide a package solution in due course.

\documentclass{article}
\usepackage{catoptions}
\makeatletter
\def\figureautorefname{figure}
\def\tableautorefname{table}
\def\Autoref#1{%
  \begingroup
  \edef\reserved@a{\cpttrimspaces{#1}}%
  \ifcsndefTF{r@#1}{%
    \xaftercsname{\expandafter\testreftype\@fourthoffive}
      {r@\reserved@a}.\\{#1}%
  }{%
    \ref{#1}%
  }%
  \endgroup
}
\def\testreftype#1.#2\\#3{%
  \ifcsndefTF{#1autorefname}{%
    \def\reserved@a##1##2\@nil{%
      \uppercase{\def\ref@name{##1}}%
      \csn@edef{#1autorefname}{\ref@name##2}%
      \autoref{#3}%
    }%
    \reserved@a#1\@nil
  }{%
    \autoref{#3}%
  }%
}
\makeatother

% Example:
\usepackage{booktabs,caption,xcolor}
\usepackage[colorlinks]{hyperref}

\begin{document}
\def\withop#1#2{With \texttt{\string#1}: #1{#2}\par}
\section{Test section}
\parindent0pt
\label{xx}
\withop\autoref{xx}
\withop\Autoref{xx}

\subsection{Test subsection}
\label{yy}
\withop\autoref{yy}
\withop\Autoref{yy}
\withop\autoref{tab:1}
\withop\Autoref{tab:1}
\withop\autoref{fig:1}
\withop\Autoref{fig:1}

\begin{table}[!h]
\centering
\caption{Sample table}\label{tab:1}
\begin{tabular}{l|l}
...&...
\end{tabular}
\end{table}

\begin{figure}[!h]
...
\end{figure}

\end{document} 

enter image description here

share|improve this answer
3  
As of fall 2013 the current hyperref version is from 2012-11-06 (6.83m) and does not feature an \Autoref AFAICS. Where did he say to provide one in the future or did I understand you wrong? –  stefanct Dec 27 '13 at 21:47
    
This works well with the default autoref names, but I have problems with custom names. Example: adding \def\subsectionautorefname{myprettyname} after the \begin{document} line will make the lower case autoref show myprettyname but the upper case Autoref Subsection. Is there an easy fix? –  Klaus Kopec Apr 24 at 12:05

There is no easy way around this, without going as far as to redefine \lstnumberautorefname to Line or including additional packages. To that extent, you might just as well be better off using

\hyperref[sdd_1]{Line~\ref*{sdd_1}}

without having to resort to the other methods. This will provide the same linkage, but capitalized. \ref* works just like \ref but does not include a hyperlink. The hyperlink is provided by \hyperref[<label>]{<stuff>}. Here is a minimal example:

enter image description here

\documentclass{article} 
\usepackage{hyperref}% http://ctan.org/pkg/hyperref
\usepackage{listings}% http://ctan.org/pkg/listings
\lstset{numbers=left,escapeinside=||}
\providecommand*{\lstnumberautorefname}{line}
\begin{document}
\begin{lstlisting} 
|\label{sdd_1}|<sqlCallStatistics>YES</sqlCallStatistics>
\end{lstlisting}
Here is some text. \hyperref[sdd_1]{Line~\ref*{sdd_1}} is important, and so is \autoref{sdd_1}.
\end{document}​
share|improve this answer
    
One day you win, one day you loose. Thanky you all for the help. –  user9131 Nov 10 '11 at 12:28

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.