GeneralAlter the \ref result appearance?

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
karlisrepsons
Posts: 50
Joined: Sat May 23, 2009 10:13 pm

Alter the \ref result appearance?

Post by karlisrepsons »

Hello comrades,
maybe you can take a look at this short and compilable example, which needs one single improvement: to make that \ref produce "II 1." instead of "1." -

Code: Select all

Code, edit and compile here:
\documentclass[a4paper,10pt]{report}
\usepackage[colorlinks=true]{hyperref}
\renewcommand{\thechapter}{\Roman{chapter}}
\renewcommand{\thesection}{\arabic{section}.}
\begin{document}
\tableofcontents
\chapter{first}
\ref{sesect}
\chapter{second}
\section{sesect}
\label{sesect}
\end{document}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
A side note:
I was willing to somehow address people in this community with a single word, but didn't find anything more appropriate than ("comrade" minus all of the associations with any particular place or time), can anyone suggest something or (according to wikipedia), I just became a communist for US readers as the sole result of it?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
php1ic
Posts: 192
Joined: Wed Jan 28, 2009 8:17 pm

Alter the \ref result appearance?

Post by php1ic »

As you are already using the hyperref package, use it's own referencing syntax. The star(*) produces the correct number without creating a 'new' internal link.

Code: Select all

Code, edit and compile here:
\documentclass[a4paper,10pt]{report}
\usepackage[colorlinks=true]{hyperref}
\renewcommand{\thechapter}{\Roman{chapter}}
\renewcommand{\thesection}{\arabic{section}.}
\begin{document}
\tableofcontents
\chapter{first}
\ref{sesect} -- \hyperref[sesect]{\ref*{sechap}~\ref*{sesect}}
\chapter{second}\label{sechap}
\section{sesect}
\label{sesect}
\end{document}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
karlisrepsons
Posts: 50
Joined: Sat May 23, 2009 10:13 pm

Re: Alter the \ref result appearance?

Post by karlisrepsons »

Thanks for effort! However, there is one thing in my way to use that -- not only it requires labelling chapters, it takes the same format of section numbering. For example: I numerate sections to end with period, but don't want it to appear in ref-s. So I'd need to access the counters out of label names... Perhaps too complicated (since it would take some "if"s too), I don't know.
karlisrepsons
Posts: 50
Joined: Sat May 23, 2009 10:13 pm

Alter the \ref result appearance?

Post by karlisrepsons »

This is doing quite well:

Code: Select all

\newcommand{\fullref}[2]{\hyperref[#2]{\fontspec{\mydefaultfontname}\ref*{#1}~\ref*{#2}}}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
But... Is it uncommon to think, that section headlines should be numbered with '.' in the end, not to confuse with a headline like "13 deamons"? However, in text those numbers again seem better to be without that period in the end. Still I wonder how could I make a command, which adds the chapter number and removes period?
jaykemper
Posts: 22
Joined: Wed Apr 15, 2009 12:11 am

Alter the \ref result appearance?

Post by jaykemper »

I had a similar question, but I'll ask it in a more general format.

If I had a label that would normally reference as "3", how would I get it "(See item 3)", or some other arbitrary format?

I notice that in the package "enumitem", it adds an optional argument to change the labelling of the enumeration and how it's referenced.

Code: Select all

Code, edit and compile here:
\documentclass{article}
\usepackage{enumitem}
\begin{document}
\section{The section}
\label{sec:list}
\begin{enumerate}[label=I\arabic{*}., ref=(See item \arabic{*})]
\item\label{item:this} This one.
\item\label{item:that} That one.
\item\label{item:other} The other one.
\end{enumerate}
A reference to this \ref{item:this} in section \ref{sec:list}.
\end{document}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
So I guess this is possible, but don't know the mechanics of it.
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Alter the \ref result appearance?

Post by cgnieder »

If you know the name of the counter that is referenced, you can use the varioref package:

Code: Select all

Code, edit and compile here:
\documentclass{article}
\usepackage{varioref}
\newcounter{mycounter}
\newcommand\test{\refstepcounter{mycounter}}
\labelformat{mycounter}{Look here:\ #1}
\begin{document}
\test\label{a}\ref{a}
\test\label{b}\ref{b}
\test\label{c}\ref{c}
\end{document}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
site moderator & package author
Post Reply