
A pergunta é feita após o MWE.
\documentclass[10pt,a4paper]{article}
\usepackage{amsmath,amsfonts}
\usepackage[framemethod=tikz]{mdframed}
\usepackage[colorlinks=true, linktocpage=false]{hyperref}
\hypersetup{
citecolor = {blue}
}
\makeatletter
\newcommand{\manuallabel}[2]{\def\@currentlabel{#2}\label{#1}}
\makeatother
\newenvironment{ProblemSpecBox}[2]
{%
\begin{mdframed}[innerlinewidth=0.5pt,%
innerleftmargin=10pt, innerrightmargin=10pt,%
innertopmargin = 10pt, innerbottommargin=10pt,%
skipabove=\dimexpr\topsep+\ht\strutbox\relax,%
roundcorner=5pt, frametitle={#1},%
frametitlerule=true, frametitlerulewidth=1pt]
{#2}
\end{mdframed}
}
\begin{document}
This is a test example
\begin{ProblemSpecBox} \manuallabel{prob:ProblemO}{Problem O} % I think this is where the problem is.
{
Problem O for $\mathbb{C}$
}
{
\emph{Given} $a, b \in \mathbb{C}$; \emph{Find} $n \in \mathbb{Z}$ such that
\[
|a|^{n} = |b|
\]
}
\end{ProblemSpecBox}
\ref{prob:ProblemO} % This must display Problem O i.e., the second argument of \manuallabel which will be linked to it's source by hyperref.
\end{document}
Sem o \manuallabel
comando comando após ProblemSpecBox
ambiente, tudo funciona bem. No entanto, se eu incluir \manuallabel
o que será posteriormente referenciado \ref{ProblemO}
conforme respondido nesta perguntaDefinir valores de referência manualmenteEu recebo os seguintes erros:
! O argumento de \manuallabel possui um } extra.
! O parágrafo terminou antes de \manuallabel ser concluído.
Eu apreciaria se alguém pudesse me ajudar a resolver este problema.
Responder1
Em vez de definir um novo \label
comando, você pode simplesmente alterar o nome do rótulo na declaração do ambiente.
Além disso, você não está usando o \newenvironment
comando corretamente, nem este novo ambiente corretamente porque você colocou \manuallabel
entre o início do ambiente e seu argumento obrigatório.
Aqui está o código com esses poucos problemas corrigidos:
\documentclass[10pt,a4paper]{article}
\usepackage{amsmath,amsfonts}
\usepackage[framemethod=tikz]{mdframed}
\usepackage[colorlinks=true, linktocpage=false]{hyperref}
\hypersetup{
citecolor = {blue}
}
\makeatletter
\newenvironment{ProblemSpecBox}[1]{
\protected@edef\@currentlabelname{#1}
\protected@edef\@currentlabel{#1}
\begin{mdframed}[
innerlinewidth=0.5pt,
innerleftmargin=10pt,
innerrightmargin=10pt,
innertopmargin = 10pt,
innerbottommargin=10pt,
skipabove=\dimexpr\topsep+\ht\strutbox\relax,
roundcorner=5pt,
frametitle={#1},
frametitlerule=true,
frametitlerulewidth=1pt]
}{
\end{mdframed}
}
\makeatother
\begin{document}
This is a test example:
\begin{ProblemSpecBox}{Problem O}
\label{prob:ProblemO}
\emph{Given} $a, b \in \mathbb{C}$; \emph{Find} $n \in \mathbb{Z}$ such that
\[
|a|^{n} = |b|
\]
\end{ProblemSpecBox}
Reference: \ref{prob:ProblemO}
\end{document}
Termo aditivo
Conforme solicitado por @evansdoe, o título e o nome de referência precisam ser diferentes, o que a resposta acima não permite. O código a seguir funciona da mesma maneira que o anterior, mas também permite argumentos opcionais na declaração do ambiente que personalizarão o rótulo de referência. Se nenhum rótulo de referência personalizado for especificado, o título será usado.
\documentclass[10pt,a4paper]{article}
\usepackage{amsmath,amsfonts}
\usepackage[framemethod=tikz]{mdframed}
\usepackage[colorlinks=true, linktocpage=false]{hyperref}
\hypersetup{
citecolor = {blue}
}
\makeatletter
\def\ProblemSpecBox{
\@ifnextchar[\ProblemSpecBox@opt{\ProblemSpecBox@noopt}}
\def\ProblemSpecBox@opt[#1]#2{
\protected@edef\@currentlabelname{#1}
\protected@edef\@currentlabel{#1}
\begin{mdframed}[
innerlinewidth=0.5pt,
innerleftmargin=10pt,
innerrightmargin=10pt,
innertopmargin = 10pt,
innerbottommargin=10pt,
skipabove=\dimexpr\topsep+\ht\strutbox\relax,
roundcorner=5pt,
frametitle={#2},
frametitlerule=true,
frametitlerulewidth=1pt]
}
\def\ProblemSpecBox@noopt#1{
\ProblemSpecBox@opt[#1]{#1}
}
\def\endProblemSpecBox{
\end{mdframed}
}
\makeatother
\begin{document}
This is a test example:
\begin{ProblemSpecBox}[Problem 0]{Problem 0 in \(\mathbb{C}\)}
\label{prob:ProblemO}
\emph{Given} $a, b \in \mathbb{C}$; \emph{Find} $n \in \mathbb{Z}$ such that
\[
|a|^{n} = |b|
\]
\end{ProblemSpecBox}
Reference: \ref{prob:ProblemO}
\end{document}
Responder2
Com uma pequena modificação na resposta do @jpellis, isso resolve o problema.
\documentclass[10pt,a4paper]{article}
\usepackage{amsmath,amsfonts}
\usepackage[framemethod=tikz]{mdframed}
\usepackage[colorlinks=true, linktocpage=false]{hyperref}
\hypersetup{
citecolor = {blue}
}
\makeatletter
\newenvironment{ProblemSpecBox}[2]{ % Takes two arguments and not one
\protected@edef\@currentlabelname{#2}
\protected@edef\@currentlabel{#2}
\begin{mdframed}[
innerlinewidth=0.5pt,
innerleftmargin=10pt,
innerrightmargin=10pt,
innertopmargin = 10pt,
innerbottommargin=10pt,
skipabove=\dimexpr\topsep+\ht\strutbox\relax,
roundcorner=5pt,
frametitle={#1},
frametitlerule=true,
frametitlerulewidth=1pt]
}{
\end{mdframed}
}
\makeatother
\begin{document}
This is a test example:
\begin{ProblemSpecBox}{Problem O for \mathbb{C}}{Problem O}
\label{prob:ProblemO}
\emph{Given} $a, b \in \mathbb{C}$; \emph{Find} $n \in \mathbb{Z}$ such that
\[
|a|^{n} = |b|
\]
\end{ProblemSpecBox}
Reference: \ref{prob:ProblemO}
\end{document}
Observe que na resposta do @jpellis o título e a referência são iguais aos de
No entanto, a resposta correta produzida pelo código LaTeX acima dá
que responde à pergunta.