How to define two labels inside an environment to compute the number of pages the environment spans?
up vote
1
down vote
favorite
I would like to count the number of pages that a certain environment (named myenv
) spans.
In principle, I set two labels, one in the beginning and one in the end of the environment.
These labels should be unique for every call of the environment, which is the part that
still fails (.tex:19: Missing endcsname inserted
):
documentclass{scrartcl}
usepackage{blindtext}
% adapted from https://tex.stackexchange.com/questions/38139/how-can-i-calculate-the-difference-of-2-counters-pageref
usepackage{refcount}
newcommand{pageRange}[2]{%
numbernumexprgetpagerefnumber{#2}-getpagerefnumber{#1}+1relax}
newcounter{howOftenCalled}% counts how often the environment 'myenv' was called (to create unique labels)
setcounter{howOftenCalled}{0}
newenvironment{myenv}[1]{
stepcounter{howOftenCalled}% increase counter
label{startPage:ref{howOftenCalled}}% define the first label
{LARGE The following text covers pageRange{startPage:ref{howOftenCalled}}{endPage:ref{howOftenCalled}} pages:}\% compute the number of pages between the first and the second label
blindtext[#1]
}{label{endPage:ref{howOftenCalled}}clearpage}% defined the second label
begin{document}
begin{myenv}{8}
end{myenv}
clearpage
begin{myenv}{15}
end{myenv}
end{document}
environments counters labels
add a comment |
up vote
1
down vote
favorite
I would like to count the number of pages that a certain environment (named myenv
) spans.
In principle, I set two labels, one in the beginning and one in the end of the environment.
These labels should be unique for every call of the environment, which is the part that
still fails (.tex:19: Missing endcsname inserted
):
documentclass{scrartcl}
usepackage{blindtext}
% adapted from https://tex.stackexchange.com/questions/38139/how-can-i-calculate-the-difference-of-2-counters-pageref
usepackage{refcount}
newcommand{pageRange}[2]{%
numbernumexprgetpagerefnumber{#2}-getpagerefnumber{#1}+1relax}
newcounter{howOftenCalled}% counts how often the environment 'myenv' was called (to create unique labels)
setcounter{howOftenCalled}{0}
newenvironment{myenv}[1]{
stepcounter{howOftenCalled}% increase counter
label{startPage:ref{howOftenCalled}}% define the first label
{LARGE The following text covers pageRange{startPage:ref{howOftenCalled}}{endPage:ref{howOftenCalled}} pages:}\% compute the number of pages between the first and the second label
blindtext[#1]
}{label{endPage:ref{howOftenCalled}}clearpage}% defined the second label
begin{document}
begin{myenv}{8}
end{myenv}
clearpage
begin{myenv}{15}
end{myenv}
end{document}
environments counters labels
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I would like to count the number of pages that a certain environment (named myenv
) spans.
In principle, I set two labels, one in the beginning and one in the end of the environment.
These labels should be unique for every call of the environment, which is the part that
still fails (.tex:19: Missing endcsname inserted
):
documentclass{scrartcl}
usepackage{blindtext}
% adapted from https://tex.stackexchange.com/questions/38139/how-can-i-calculate-the-difference-of-2-counters-pageref
usepackage{refcount}
newcommand{pageRange}[2]{%
numbernumexprgetpagerefnumber{#2}-getpagerefnumber{#1}+1relax}
newcounter{howOftenCalled}% counts how often the environment 'myenv' was called (to create unique labels)
setcounter{howOftenCalled}{0}
newenvironment{myenv}[1]{
stepcounter{howOftenCalled}% increase counter
label{startPage:ref{howOftenCalled}}% define the first label
{LARGE The following text covers pageRange{startPage:ref{howOftenCalled}}{endPage:ref{howOftenCalled}} pages:}\% compute the number of pages between the first and the second label
blindtext[#1]
}{label{endPage:ref{howOftenCalled}}clearpage}% defined the second label
begin{document}
begin{myenv}{8}
end{myenv}
clearpage
begin{myenv}{15}
end{myenv}
end{document}
environments counters labels
I would like to count the number of pages that a certain environment (named myenv
) spans.
In principle, I set two labels, one in the beginning and one in the end of the environment.
These labels should be unique for every call of the environment, which is the part that
still fails (.tex:19: Missing endcsname inserted
):
documentclass{scrartcl}
usepackage{blindtext}
% adapted from https://tex.stackexchange.com/questions/38139/how-can-i-calculate-the-difference-of-2-counters-pageref
usepackage{refcount}
newcommand{pageRange}[2]{%
numbernumexprgetpagerefnumber{#2}-getpagerefnumber{#1}+1relax}
newcounter{howOftenCalled}% counts how often the environment 'myenv' was called (to create unique labels)
setcounter{howOftenCalled}{0}
newenvironment{myenv}[1]{
stepcounter{howOftenCalled}% increase counter
label{startPage:ref{howOftenCalled}}% define the first label
{LARGE The following text covers pageRange{startPage:ref{howOftenCalled}}{endPage:ref{howOftenCalled}} pages:}\% compute the number of pages between the first and the second label
blindtext[#1]
}{label{endPage:ref{howOftenCalled}}clearpage}% defined the second label
begin{document}
begin{myenv}{8}
end{myenv}
clearpage
begin{myenv}{15}
end{myenv}
end{document}
environments counters labels
environments counters labels
asked 1 hour ago
Marius Hofert
1,99512445
1,99512445
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
Your code works except that you cannot retrieve the value of your counter with ref{howOftenCalled}
. If you use thehowOftenCalled}
instead, everything works as expected.
documentclass{scrartcl}
usepackage{blindtext}
% adapted from https://tex.stackexchange.com/questions/38139/how-can-i-calculate-the-difference-of-2-counters-pageref
usepackage{refcount}
newcommand{pageRange}[2]{%
numbernumexprgetpagerefnumber{#2}-getpagerefnumber{#1}+1relax}
newcounter{howOftenCalled}% counts how often the environment 'myenv' was called (to create unique labels)
setcounter{howOftenCalled}{0}
newenvironment{myenv}[1]{%
stepcounter{howOftenCalled}% increase counter
label{startPage:thehowOftenCalled}% define the first label
{LARGE The following text covers
pageRange{startPage:thehowOftenCalled}{endPage:thehowOftenCalled} pages:}\% compute the number of pages between the first and the second label
blindtext[#1]
}{label{endPage:thehowOftenCalled}clearpage}% defined the second label
begin{document}
begin{myenv}{8}
end{myenv}
clearpage
begin{myenv}{15}
end{myenv}
end{document}
top of p. 1:
top of p. 3:
Note that you may have to remove the aux file if you just copy this code into your old file that caused the problem.
– marmot
31 mins ago
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Your code works except that you cannot retrieve the value of your counter with ref{howOftenCalled}
. If you use thehowOftenCalled}
instead, everything works as expected.
documentclass{scrartcl}
usepackage{blindtext}
% adapted from https://tex.stackexchange.com/questions/38139/how-can-i-calculate-the-difference-of-2-counters-pageref
usepackage{refcount}
newcommand{pageRange}[2]{%
numbernumexprgetpagerefnumber{#2}-getpagerefnumber{#1}+1relax}
newcounter{howOftenCalled}% counts how often the environment 'myenv' was called (to create unique labels)
setcounter{howOftenCalled}{0}
newenvironment{myenv}[1]{%
stepcounter{howOftenCalled}% increase counter
label{startPage:thehowOftenCalled}% define the first label
{LARGE The following text covers
pageRange{startPage:thehowOftenCalled}{endPage:thehowOftenCalled} pages:}\% compute the number of pages between the first and the second label
blindtext[#1]
}{label{endPage:thehowOftenCalled}clearpage}% defined the second label
begin{document}
begin{myenv}{8}
end{myenv}
clearpage
begin{myenv}{15}
end{myenv}
end{document}
top of p. 1:
top of p. 3:
Note that you may have to remove the aux file if you just copy this code into your old file that caused the problem.
– marmot
31 mins ago
add a comment |
up vote
0
down vote
Your code works except that you cannot retrieve the value of your counter with ref{howOftenCalled}
. If you use thehowOftenCalled}
instead, everything works as expected.
documentclass{scrartcl}
usepackage{blindtext}
% adapted from https://tex.stackexchange.com/questions/38139/how-can-i-calculate-the-difference-of-2-counters-pageref
usepackage{refcount}
newcommand{pageRange}[2]{%
numbernumexprgetpagerefnumber{#2}-getpagerefnumber{#1}+1relax}
newcounter{howOftenCalled}% counts how often the environment 'myenv' was called (to create unique labels)
setcounter{howOftenCalled}{0}
newenvironment{myenv}[1]{%
stepcounter{howOftenCalled}% increase counter
label{startPage:thehowOftenCalled}% define the first label
{LARGE The following text covers
pageRange{startPage:thehowOftenCalled}{endPage:thehowOftenCalled} pages:}\% compute the number of pages between the first and the second label
blindtext[#1]
}{label{endPage:thehowOftenCalled}clearpage}% defined the second label
begin{document}
begin{myenv}{8}
end{myenv}
clearpage
begin{myenv}{15}
end{myenv}
end{document}
top of p. 1:
top of p. 3:
Note that you may have to remove the aux file if you just copy this code into your old file that caused the problem.
– marmot
31 mins ago
add a comment |
up vote
0
down vote
up vote
0
down vote
Your code works except that you cannot retrieve the value of your counter with ref{howOftenCalled}
. If you use thehowOftenCalled}
instead, everything works as expected.
documentclass{scrartcl}
usepackage{blindtext}
% adapted from https://tex.stackexchange.com/questions/38139/how-can-i-calculate-the-difference-of-2-counters-pageref
usepackage{refcount}
newcommand{pageRange}[2]{%
numbernumexprgetpagerefnumber{#2}-getpagerefnumber{#1}+1relax}
newcounter{howOftenCalled}% counts how often the environment 'myenv' was called (to create unique labels)
setcounter{howOftenCalled}{0}
newenvironment{myenv}[1]{%
stepcounter{howOftenCalled}% increase counter
label{startPage:thehowOftenCalled}% define the first label
{LARGE The following text covers
pageRange{startPage:thehowOftenCalled}{endPage:thehowOftenCalled} pages:}\% compute the number of pages between the first and the second label
blindtext[#1]
}{label{endPage:thehowOftenCalled}clearpage}% defined the second label
begin{document}
begin{myenv}{8}
end{myenv}
clearpage
begin{myenv}{15}
end{myenv}
end{document}
top of p. 1:
top of p. 3:
Your code works except that you cannot retrieve the value of your counter with ref{howOftenCalled}
. If you use thehowOftenCalled}
instead, everything works as expected.
documentclass{scrartcl}
usepackage{blindtext}
% adapted from https://tex.stackexchange.com/questions/38139/how-can-i-calculate-the-difference-of-2-counters-pageref
usepackage{refcount}
newcommand{pageRange}[2]{%
numbernumexprgetpagerefnumber{#2}-getpagerefnumber{#1}+1relax}
newcounter{howOftenCalled}% counts how often the environment 'myenv' was called (to create unique labels)
setcounter{howOftenCalled}{0}
newenvironment{myenv}[1]{%
stepcounter{howOftenCalled}% increase counter
label{startPage:thehowOftenCalled}% define the first label
{LARGE The following text covers
pageRange{startPage:thehowOftenCalled}{endPage:thehowOftenCalled} pages:}\% compute the number of pages between the first and the second label
blindtext[#1]
}{label{endPage:thehowOftenCalled}clearpage}% defined the second label
begin{document}
begin{myenv}{8}
end{myenv}
clearpage
begin{myenv}{15}
end{myenv}
end{document}
top of p. 1:
top of p. 3:
answered 1 hour ago
marmot
77.1k487162
77.1k487162
Note that you may have to remove the aux file if you just copy this code into your old file that caused the problem.
– marmot
31 mins ago
add a comment |
Note that you may have to remove the aux file if you just copy this code into your old file that caused the problem.
– marmot
31 mins ago
Note that you may have to remove the aux file if you just copy this code into your old file that caused the problem.
– marmot
31 mins ago
Note that you may have to remove the aux file if you just copy this code into your old file that caused the problem.
– marmot
31 mins ago
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f461363%2fhow-to-define-two-labels-inside-an-environment-to-compute-the-number-of-pages-th%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown