I wrote my own environment "theorem" with the package environ for key arguments and was recently stuck at two problems: How to insert citation as an argument and how to do it with a label?
The situation is as folows: When referencing to the theorem, I didn't just want to get the number, but the text "theorem 1.1" (where 1.1 is the correct number of the theorem). I did not like it, that in other environments you first write a label as BODY, so I wanted to include this as an argument. This works fine when I use the name of the label as argument (\mytheorem@label
) and write this inside the code for the environment as \label{\mytheorem@label}
. But this has the disadvantage that when writing a document, I don't get the list of labels when tiping \ref{}
. Therefore I wanted to replace the code snippet in the environment by giving [label=\label{randomStuff}]
as argument.
Problem is that just won't work. It gives back the error, that something in the label was never defined. I recently had the same problem with citation (the result should look like theorem 1.1 (see [1]), where [1] is the first citation) and after trying \expandafter
and \protect
, which I just always try because they seem important, I found that a simple \begin{mytheorem}[{cite=\cite{firstBook}}]
does the trick. So I tried something similiar to this, but it didn't work.
Do you have any ideas? If there is a way to loose the parantheses around the `cite, I'd also love to hear about it. So here is an example of what I'd like to have.
\documentclass{scrartcl]
\usepackage{Environ}
\newcounter{\theoremcounter}
\define@key{mytheorem}{cite}{\def\mytheorem@cite{#1}}
\define@key{mytheorem}{label}{\def\mytheorem@label{#1}}
\NewEnviron{mytheorem}[1][]{
theorem \thesection.\theoremcounter\ \protect\theorem@cite\\
\def\@currentlabel{theorem~\thesection.\theoremcounter}{{\lemma@label}}
\BODY
}
\section{first sec}
\begin{document}
\begin{mytheorem}[label=\label{th1},cite=(see \cite{author1})]
good idea
\end{mytheorem}
As stated in \ref{th1} it is ...
\end{document}
which should give the output
1. first sec
theorem 1.1 (see [1])
good idea
As stated in theorem 1.1
Sorry, if something is unclear. I'll try to explain whatever you need. I had to make my code much smaller and I hope from this you understand what I mean.
Thanks in advance
\documentclass{article}
command which is typically the first command in LaTeX documents. Adding any content that is supposed to be printed after\end{document}
doesn't make any sense. Everything after that command is ignored. If you add\section{<name>}
before\begin{document}
it will also produce an error. The material that is supposed to be printed shall be inside thedocument
environment.