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.
\documentclass{article}
\usepackage{hyperref}
\usepackage{lipsum}
\usepackage{polski}
\begin{document}
\begin{figure}
.
\caption{A figure}
\label{fff}
\end{figure}
\lipsum[1]

Rysunek~\ref{fff} jest zabawny, bo na rysunku~\ref{fff} nic nie ma.
\end{document}

In this sample, a clickable link is added to output PDF for 1 and 1. I want to be able to change them to Rysunek 1 and rysunku 1. I want to be able to put any other text + number of the figure into a hyperlink.
The word rysunek can't be set in preamble as a default because there is a declension in Polish.
The same question goes for tables, listings, equations, pages (pageref) etc (basically any reference).

HTML equivalent of my MWE:

Rysunek <href="fff">1</a> jest zabawny, bo na rysunku <a href="fff">1</a> nic nie ma.

I want it to be:

<href="fff">Rysunek 1</a> jest zabawny, bo na <a href="fff">rysunku 1</a> nic nie ma.
share|improve this question
    
Try to use \autoref instead of \ref. –  canaaerus Jun 22 '12 at 7:35

4 Answers 4

up vote 4 down vote accepted

The explanation of \labelcref in the documentation of cleveref is not very clear, but it seems to produce only the label, without any attached string.

A possibility would be to say

\crefformat{figure}{#2\templabel~#1#3}
\DeclareRobustCommand{\casecref}[2]{%
  \begingroup\def\templabel{#1}\cref{#2}\endgroup}

so that the output of

\casecref{Rysunek}{fff} jest zabawny, bo na
\casecref{rysunku}{fff} nic nie ma.

would be what you're expecting. I'm afraid you have to set \crefformat in a similar way for all the reference types you're going to use.

share|improve this answer
    
"I'm afraid you have to set \crefformat in a similar way for all the reference types you're going to use." That's not a problem :). –  Ichibann Jun 22 '12 at 12:07
    
@egreg: With your proposed code, a user would always have to use \casecref and couldn't use \cref directly any longer, right? –  Mico Jun 22 '12 at 12:41
2  
@Mico Only for the types redeclared with \crefformat in the proposed way. However, for languages with declension it's difficult to find a better way: usually there are different terminations for the same cases. A different way might be to memorize all the declension for the required word and add a key for the case to use. –  egreg Jun 22 '12 at 12:48

Macro \hyperref also knows an optional argument. Then it expects a label name and the only mandatory argument contains the text:

\hyperref[labelname]{text made to link}

Because we have now a link, we do not need another link inside causing by \ref to the same location. Therefore \ref (and also \pageref) have a star form if hyperref is used. With star the references are set without link.

Applied to the example:

\documentclass{article}
\usepackage{hyperref}
\usepackage{lipsum}
\usepackage{polski}
\begin{document}
\begin{figure}
.
\caption{A figure}
\label{fff}
\end{figure}
\lipsum[1]

\hyperref[fff]{Rysunek~\ref*{fff}} jest zabawny,
bo na \hyperref[fff]{rysunku~\ref*{fff}} nic nie ma.
\end{document}

enter image description here

share|improve this answer

Your best option may be to use the cleveref package. To include the "name" of the item being cross-referenced in the hyperlink target, you'll need to load it with the nameinlink option:

\usepackage[nameinlink]{cleveref}

Remember that it's necessary to load the cleveref package after the hyperref package (and any other packages that manipulate the \label macro). With this package loaded, and supposing you have two equations labelled, say, {eq:a} and {eq:b}, you would cross-refernce the first one by issuing the command \cref{eq:a}, or both at once with the command \cref{eq:a,eq:b}.

However, the fact that language of your documents would appear to be Polish raises (at least) two complications.

  • First, the default language the cleveref package employs for cross-referenced items ("equation", "figure", "table", "page", etc) is English. Currently, the package includes options to use about a dozen other languages to typeset the names of cross-referenced items, but Polish is not (yet) one of them. Aside: If you contacted Toby Cubitt (the author of the cleveref package) and sent him a list of item names in Polish, I'm sure he'd be delighted to set up a new, Polish, language option. (The items include: equation, figure, subfigure, table, subtable, page, part, chapter, section, appendix, enumi, footnote, theorem, lemma, corollary, proposition, definition, result, example, remark, note, algorithm, listing, and line!)

    In the meantime, though, you'll have to use some of the low-level controls of the cleveref package to supply all the names (in nominative singular and nominative plural forms) yourself. E.g., in the preamble after loading the package, you'd have to enter commands of the form (using English just for this example)

    \crefname{equation}{equation}{equations}  %substitute Polish equivalents here...
    \Crefname{equation}{Equation}{Equations} 
    \crefname{figure}{Figure}{Figures}
    \Crefname{figure}{Figure}{Figures}
    

    and so on.

  • Second, Polish is a language that declines nouns, i.e., the nominative, genetive, etc forms are generally different, right? The user guide for the cleveref has this to say for use of the cleveref package with such languages:

Note that if you're writing in a language in which nouns decline, the \cref and \cpageref commands may be less useful, as they always produce the cross-reference name in the nominative case. In such languages, you may instead prefer to use the \labelcref and \labelcpageref commands. Unlike \cref and \cpageref, these don't produce the name in front of the cross-reference, so you must supply it (in the appropriate case) yourself. But they do still cope with multi-references, so you still gain some benefit from using cleveref.

In short, be prepared to use the \labelcref command at times and supply the associated noun's name yourself in the appropriate (non-nominative) case. Or, rephrase your sentences that contain cross-references so that they only use the nominative cases.

Addendum: To use \labelcref instead of \cref, you would type of Figures~\labelcref{fig:a,fig:b} instead of of \cref{fig:a,fig:b}. A side-effect of this construction is that the noun (here, Figures) that precedes the \labelcref command will not be part of the hyperlink even if the nameinlink option was set.

share|improve this answer
    
What is \labelcref syntax? i'm unable to find it in http://mirrors.ctan.org/macros/latex/contrib/cleveref/cleveref.pdf. –  Ichibann Jun 22 '12 at 10:47
    
Ummm, I find instances of \labelcref on pages 4, 7, 17, etc of that document... Anyway, \labelcref acts exactly like \cref except that it doesn't prefix the name of the cross-referenced item (or items) to the label(s). –  Mico Jun 22 '12 at 10:50
    
Yes, \labelcref is mentioned on those pages, but I'm still unable to find information how to use this. Should I put \labelcref{fff}? I don't think so. Where should I put my rysunek word to get [HTML equivalent] <a href="fff">rysunek 1</a>? I can only get rysunek <a href="fff">1</a> (posted in question) –  Ichibann Jun 22 '12 at 11:25
    
@Ichibann: please see the addendum to my answer. –  Mico Jun 22 '12 at 11:54
    
Mico, you said: "A side-effect of this construction is that the noun [...] will not be part of the hyperlink even if the nameinlink option was set." So what's the point? In my MWE I already have a noun which is not part of a hyperlink... The point of my question is to put this noun into a hyperlink. –  Ichibann Jun 22 '12 at 11:57

You should look at the cleveref package : http://mirrors.ircam.fr/pub/CTAN/help/Catalogue/entries/cleveref.html

It determines automatically the type of a cross reference. Thus

\ref{apicture}

will give : Figure N instead of just the number of the figure.

EDIT : an other possibility which is less automatic is the use of fncylab package. Here is an example which define the behavior of the \ref command for floats : figure, table, equation and codesource (a custum float previously defined).

\usepackage{fncylab}
\labelformat{figure}{\sffamily \figurename~#1}
\labelformat{table}{\tablename~#1}
\labelformat{equation}{\sffamily équation~#1}
\labelformat{codesource}{\sffamily code source~#1}

If I well understand this do what you want, hereafter is an output example where you can see that the link include eqution 4.6 : enter image description here

share|improve this answer
    
Ok, but I want to put any text into a hyperlink. –  Ichibann Jun 22 '12 at 7:21
1  
hyperref package : \href{http://www.alink.org}{a name}. Is it specific to crossreference or not ? I edit my answer with fncylab possibilities. –  Ger Jun 22 '12 at 7:31
    
Yes, that is much better but still not what I want. For example I might want to put into figure's label Rysunek and another time rysunku (due to declension) or another time ungabunga just because I could. Is that possible? –  Ichibann Jun 22 '12 at 8:04
    
I do not understand anythink about your language :) but nevertheless, a trick could be to define differents float environment. For example, one for Rysunek and one for ungabunga. For the declension (pluriel I guess ?) I do not have idea. When I used fncylab, I wrote for example Rysunek 1 and Rysunek 2 ... –  Ger Jun 22 '12 at 8:41
    
Why define anything for every environment? I just want to wrote something like: Na \newref{rysunku}{fig:fff} jest ładnie. Declension is not just plural, BTW. In Polish (and many other languages) form of a noun depends on grammatical case. For example "rysunek" (the figure) is Nominative case and "[na] rysunku" is Locative case ([on] this figure). –  Ichibann Jun 22 '12 at 9:06

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.