0

I want a code that can provide a link (ref) to a theorem with text which follows these conditions:

1.) If the theorem have a name (like \begin{theorem}[name]\end{theprem}), the text will be name Theorem.

2.) Otherwise, the text will be Theorem 1.1. (the number of the theorem).

I will be very gladful if someone can write me that code. Thank you.

1

Here is a way (as far as I understood the question):

\documentclass{article}
\usepackage{amsmath}
\usepackage{lipsum}
\def\thname{name}
\newtheorem{theorem}{Theorem}[section]%added section after edit and picture
\newtheorem{mytheorem}{\thname{} Theorem}
\newenvironment{mtheorem}[1][name]{\def\thname{#1}\mytheorem}{\endmytheorem}
\def\themytheorem{:}

\begin{document}
\section{Test Section}
\begin{theorem}
\lipsum[1]
\end{theorem}
\begin{mtheorem}[Some]
\lipsum[1]
\end{mtheorem}
\begin{mtheorem}[Some Other]
\lipsum[1]
\end{mtheorem}
\begin{theorem}
\lipsum[1]
\end{theorem}

\end{document}

enter image description here

|improve this answer|||||
  • Edited the code but not the screenshot in order to have theorem within section... ie 1.1, 1.2 etc – koleygr Aug 11 '19 at 1:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.