3

i would like add some auto text to figure numbers according to the (automatic) reference numbers.

a minimal example.

\documentclass{article}

\begin{document}

\begin{figure}
\centering
\rule{1cm}{1cm}
\caption{This is figure 1}
\label{fig1}
\end{figure}

\begin{figure}
    \centering
    \rule{1cm}{1cm}
    \caption{This is figure 2}
    \label{fig2}
\end{figure}

\begin{figure}
    \centering
    \rule{1cm}{1cm}
    \caption{This is figure 3}
    \label{fig3}
\end{figure}

i want to get "figure (1)'de" when i write " figure (\ref{fig1})",\\
i want to get "figure (2)'se" when i write "figure (\ref{fig2})",\\
i want to get "figure (3)'te" when i write "figure (\ref{fig3})" 

\end{document}
mert
  • 1,667
  • \usepackage{cleveref} and \cref{fig1} etc. instead of \ref{fig1} etc., if you're using hyperref as well, include cleveref after hyperref! –  Aug 21 '16 at 15:18
  • @ChristianHupfer: but he wants parentheses as well, so you may want to point out the cleveref commands that accomplish that. I'd provide an answer, but..... ;-) – JPi Aug 22 '16 at 02:49
  • @ChristianHupfer Rather than having the word "figure" appear automatically, the main point of the question seems to be that the de, seand te endings should appear after the figure number. I don't think that cleveref will do this, at least not without some help. –  Aug 22 '16 at 03:53
  • 1
    @Andrew: It should be possible with cleveref \crefformat command as well, but you answered it already, so no need to add another answer –  Aug 22 '16 at 17:16
  • @ChristianHupfer Ah, thanks, didn't know about \crefformat. –  Aug 22 '16 at 22:40
  • @Andrew: thanks. could you explain how to get this in a section numbered document, please? namely "1.1'de" "1.2'se" "1.3'te" .... "2.1'de" "2.2'se"..... – mert Aug 23 '16 at 08:23

1 Answers1

3

As I understand the question, a suffix of de, se or te should appear after the figure number. I have defined a macro \fref that adds these suffixes automatically, assuming that the suffix should still be te if the figure number is greater than or equal to 3. As a bonus, the macro automatically adds the word "Figure" to the reference.

Here is the output:

enter image description here

and here is the code:

\documentclass{article}
\usepackage{refcount}
\newcommand\fref[1]{%
  Figure~(\getrefnumber{#1})`\ifcase\getrefnumber{#1}\or de\or se\else te\fi}

\begin{document}

\begin{figure}
\centering
\rule{1cm}{1cm}
\caption{This is figure 1}
\label{fig1}
\end{figure}

\begin{figure}
    \centering
    \rule{1cm}{1cm}
    \caption{This is figure 2}
    \label{fig2}
\end{figure}

\begin{figure}
    \centering
    \rule{1cm}{1cm}
    \caption{This is figure 3}
    \label{fig3}
\end{figure}

\begin{figure}
    \centering
    \rule{1cm}{1cm}
    \caption{This is figure 4}
    \label{fig4}
\end{figure}

Reference for fig1: \fref{fig1}.

Reference for fig2: \fref{fig2}.

Reference for fig3: \fref{fig3}.

Reference for fig4: \fref{fig4}.

\end{document}

One caveat, this works with your MWE but if the figure number includes a chapter or section number, so that it looks like 3.4 for example, then this will need to be modified.

EDIT

As highlighted already the solution above will not work if the figure numbers include a section or chapter number. Following Gonzalo Medina, here is one way of dealing with this case:

\documentclass{amsart}
\numberwithin{figure}{section}

\usepackage{refcount}
\usepackage{xstring}
\newcommand\fref[1]{\IfRefUndefinedExpandable{#1}{??}{Figure~(\ref{#1})`\addrefending{#1}}}
\newcommand\addrefending[1]{\StrBehind{\getrefnumber{#1}}{.}[\fignumber]%
  \ifcase\fignumber\relax\or de\or se\else te\fi}

\begin{document}

\section{Section with figures}
\begin{figure}
\centering
\rule{1cm}{1cm}
\caption{This is figure 1}
\label{fig1}
\end{figure}

\begin{figure}
    \centering
    \rule{1cm}{1cm}
    \caption{This is figure 2}
    \label{fig2}
\end{figure}

\begin{figure}
    \centering
    \rule{1cm}{1cm}
    \caption{This is figure 3}
    \label{fig3}
\end{figure}

\begin{figure}
    \centering
    \rule{1cm}{1cm}
    \caption{This is figure 4}
    \label{fig4}
\end{figure}

Reference for fig1: \fref{fig1}.

Reference for fig2: \fref{fig2}.

Reference for fig3: \fref{fig3}.

Reference for fig4: \fref{fig4}.

\end{document}
  • thanks. can you explain how to get this in section numbered document, please? namely "1.1'de" "1.2'se" "1.3'te" .... "2.1'de" "2.2'se"..... – mert Aug 23 '16 at 08:06
  • 1
    @mert I have edited the post to show what to do when figures are numbered within sections. –  Aug 23 '16 at 23:16