3

Motivation: I want to declare a command \tbc (without arguments) to use it inside an environment. I want this command to produce a text like Problem 2 continues on the next page, start a new page and produce Problem 2 continued... I use a variety of environments, such as Problem, Question, Exercise, etc, but all use a continuous numbering with the counter theorem. Naturally, I want my \tbc to produce Problem 2 when it's used between \begin{problem} and \end{problem}, and Question 3 when it's used between \begin{question} and \end{question}.

Question: I know that I can get the environment number with \the\value{theorem}. I can't figure out how to get an environment name.

I am aware that there are other packages for this, but having my own small command allows me to better merge it with the style of my documents.

2 Answers 2

2

A hack that exploits amsthm: when typesetting the header, I redefine \tbcname to expand to #1 (the theorem name).

\documentclass{article}
\usepackage{amsthm}
\usepackage{lipsum}

\newtheoremstyle{definition-keep}
  {\topsep}   % ABOVESPACE
  {\topsep}   % BELOWSPACE
  {\upshape}  % BODYFONT
  {0pt}       % INDENT (empty value is the same as 0pt)
  {\bfseries} % HEADFONT
  {.}         % HEADPUNCT
  {5pt plus 1pt minus 1pt} % HEADSPACE
  {\gdef\tbcname{#1}\thmname{#1} \thmnumber{#2}\thmnote{ (#3)}} % CUSTOM-HEAD-SPEC

\newtheorem{theorem}{Theorem}
\theoremstyle{definition-keep}
\newtheorem{problem}[theorem]{Problem}
\newtheorem{exercise}[theorem]{Exercise}

\newcommand{\tbc}{%
  \par
  \textit{\tbcname~\thetheorem\ continues on the next page}\clearpage
  \textit{\tbcname~\thetheorem\ continued}\dots\par
}

\begin{document}

\begin{problem}
\lipsum[1-3]
\tbc
\lipsum[4]
\end{problem}

\end{document}

enter image description here

1

In case the names of your environments are the same as the names of the counters in use for these environments, you can use \@currenvir for obtaining the name of an environment and the counter associated to that environment.

Besides this:

  1. The varioref-package can be used for obtaining phrases like "on the next page" or "on the following page". That brings a bit of variety to the text.

  2. I think, for referencing from outside the environment the \autoref-command of the hyperref-package will be your friend.

    It will prepend names associated to counters to references.

    The names come from macros whose names are of pattern
    \⟨counter⟩autorefname
    or—in case the further macro is not defined—
    \⟨counter⟩name.
    (See section 4, Additional User Macros, of the manual of the hyperref-package.)

    But there is one small problem:

    When you use the same counter for several theorem-like environments, you need several names / several macros \⟨counter⟩autorefname for that counter.

    That problem is addressed by the package aliascnt by Heiko Oberdiek.

Here is a small example:

\documentclass{article}

%===================[adjust margins/layout for the example]====================
\paperwidth=8.91cm
\paperheight=5.25 cm
\csname @ifundefined\endcsname{pagewidth}{}{\pagewidth=\paperwidth}%
\csname @ifundefined\endcsname{pdfpagewidth}{}{\pdfpagewidth=\paperwidth}%
\csname @ifundefined\endcsname{pageheight}{}{\pageheight=\paperheight}%
\csname @ifundefined\endcsname{pdfpageheight}{}{\pdfpageheight=\paperheight}%
\textwidth=\paperwidth
\oddsidemargin=1.25cm
\marginparsep=.125\oddsidemargin
\marginparwidth=\oddsidemargin
\advance\marginparwidth-2\marginparsep
\advance\textwidth-2\oddsidemargin
\advance\oddsidemargin-1in
\evensidemargin=\oddsidemargin
\textheight=\paperheight
\topmargin=1.25cm
\footskip=.5\topmargin
{\normalfont\global\advance\footskip.5\ht\strutbox}%
\advance\textheight-2\topmargin
\advance\topmargin-1in
\headheight=0ex
\headsep=0ex
\pagestyle{plain}
\parindent=0ex
\parskip=0ex 
\topsep=0ex
\partopsep=0ex
%==================[eof margin-adjustments]====================================

\usepackage{varioref}

% In case you wish no hyperlinks and no bookmarks:
\AtBeginDocument{\NoHyper}
\usepackage[bookmarks=false]{hyperref}
% In case you wish hyperlinks and bookmarks:
%\usepackage{hyperref}

\usepackage{aliascnt}

\newtheorem{theorem}{Theorem}

% Create fake-counters that use the same count-register as the
% theorem-counter:
\newaliascnt{problem}{theorem}
\newaliascnt{question}{theorem}
\newaliascnt{exercise}{theorem}

% Define the autoref-names of the fake-counters when referencing then
% via \autoref
\newcommand\problemautorefname{Problem}
\newcommand\questionautorefname{Question}
\newcommand\exerciseautorefname{Exercise}


% Create theorem-environments that use the fake-counters:
\newtheorem{problem}[problem]{Problem}
\newtheorem{question}[question]{Question}
\newtheorem{exercise}[exercise]{Exercise}

% Apply the fix provided by the package aliascnt for \newtheorem when
% being used with a fake-counter -- see section 1, "User Interface" of
% the manual of the aliascnt-package, URL:
% <http://mirrors.ctan.org/macros/latex/contrib/oberdiek/aliascnt.pdf>
\aliascntresetthe{problem}
\aliascntresetthe{question}
\aliascntresetthe{exercise}

\makeatletter
%
% \tbc or \tbc[<referencing-command>]
%
\newcommand\tbccnt{0}%
\newcommand{\tbc}[1][\vpageref*]{%
  \par
  % globally step \tbccnt:
  \xdef\tbccnt{\number\numexpr\tbccnt+1\relax}%
  \begingroup
  % You probably wish to adjust varioref's behaviour:
  % \def\reftextfaceafter{on the next page}%
  % \def\reftextafter{on the next page}%
  \textit{%
    \csname\@currenvir autorefname\endcsname~%
    \csname the\@currenvir\endcsname\ continues \null%
    \hyperref[{tbc@continued@\tbccnt}]{#1{tbc@continued@\tbccnt}}.%
  }%
  \endgroup
  \clearpage
  \textit{%
    \phantomsection
    \label{tbc@continued@\tbccnt}%
    \csname\@currenvir autorefname\endcsname~%
    \csname the\@currenvir\endcsname\ continued%
  }\dots\par\ignorespaces
}
\makeatother

\begin{document}

\begin{theorem}
\label{Firsttheorem}
This is a theorem.
\tbc
This is a theorem.
\end{theorem}

\vfill

\begin{problem}
\label{Firstproblem}
This is a problem.
\tbc
This is a problem.
\end{problem}

\vfill

\begin{question}
\label{Firstquestion}
This is a question.
\tbc
This is a question.
\end{question}

\vfill

\begin{exercise}
\label{Firstexercise}
This is an exercise.
\tbc[on page~\pageref*]
This is an exercise.
\end{exercise}

\newpage

\noindent Referencing:

\verb|\autoref{Firsttheorem}|: \autoref{Firsttheorem}

\verb|\autoref{Firstproblem}|: \autoref{Firstproblem}

\verb|\autoref{Firstquestion|: \autoref{Firstquestion}

\verb|\autoref{Firstexercise}|: \autoref{Firstexercise}

\end{document}

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .