0

This is a follow on for an answer in: What is the correct way to type "See Eq. (n)

\documentclass[12pt]{report}   

\usepackage[UKenglish]{babel}
\usepackage{graphicx} 
\usepackage{epstopdf}    
\usepackage{gensymb}
\usepackage{amssymb}
\usepackage{stmaryrd}
\usepackage{amsmath}  
\usepackage{siunitx}
\usepackage{placeins}
\usepackage{letltxmacro}


\LetLtxMacro{\oldeqref}{\eqref}
\RenewDocumentCommand\eqref{D<>{Equation}om}{%
\IfNoValueTF{#2}
{#1~\oldeqref{#3}}
{(#2 #1~\textup{\ref{#3}})}%
}

\begin{document}

\begin{equation}
\label{eq:test}
x=2y;
\end{equation}%

what this looks like:

this is Equation~\eqref{eq:test}

this is \eqref[Equation]{eq:test}

%this is \eqref[Equation][: terms 1 and 2]{eq:test}



\end{document}

This answer does most of what I want to do, but I would like to change it so that

 \eqref[]{eqlable} 

can also take the form

\eqref[][]{eqlabel} 

so that writing can be added both before and after the equation number within the brackets. Also, I would like to not have the "Equation" in there as I've already written this throughout my document (when I don't need brackets) and adding this doubles it. If I delete this from the above - I end up with a weird space.

Defining a new command would also work - and I have seen other answers based on this - but I don't know how to edit any of them to get the before and after text working.

edit: I would like the second option to look something like

   \eqref[Equation][: terms 1 and 2]{eqlabel}

and to produce (Equation 1.1: terms 1 and 2). The brackets already get automatically added when I type [] as an option.

and for

Equation~\eqref{eqlabel} 

to produce Equation (1.1). This already works

any way to get the terms: 1 and 2 after the number in the bracket would be fine. i can change how i write Equation to match whatever works

BaiSmi
  • 25
  • Can you please make your code compilable? If there's only one optional argument, what should be done with it? – cfr Feb 18 '18 at 01:19

1 Answers1

3

I think it's working as you want :)

enter image description here

\documentclass[12pt]{report}   

\usepackage[UKenglish]{babel}
\usepackage{graphicx} 
\usepackage{epstopdf}    
\usepackage{gensymb}
\usepackage{amssymb}
\usepackage{stmaryrd}
\usepackage{amsmath}  
\usepackage{siunitx}
\usepackage{placeins}
\usepackage{letltxmacro}


%\LetLtxMacro{\oldeqref}{\eqref}
% As Christian Hupfer noted, there is no need to use \LetLtxMacro here. Although there is no harm is using it (https://tex.stackexchange.com/questions/88001/when-to-use-letltxmacro)
\let\oldeqref\eqref
\RenewDocumentCommand\eqref{oom}{%
\IfNoValueTF{#2}{\def\eqafter{}}{\def\eqafter{#2}}%
\IfNoValueTF{#1}
{\oldeqref{#3}}
{(#1 \textup{\ref{#3}}\eqafter)}%
}

\begin{document}

\begin{equation}
\label{eq:test}
x=2y;
\end{equation}%

what this looks like:

this is Equation~\eqref{eq:test}

this is \eqref[Equation]{eq:test}

this is \eqref[Equation][: terms 1 and 2]{eq:test}

\end{document}
  • 1
    As far as I know, \eqref does not have an optional argument, so no need for \LetLtxMacro -- an ordinary \let should suffice –  Feb 18 '18 at 08:55