classification labels in headers and footers Unicorn Meta Zoo #1: Why another podcast? ...

Does using the Inspiration rules for character defects encourage My Guy Syndrome?

How to keep bees out of canned beverages?

Are there existing rules/lore for MTG planeswalkers?

Stretch a Tikz tree

Is it OK if I do not take the receipt in Germany?

Philosophers who were composers?

Can gravitational waves pass through a black hole?

Married in secret, can marital status in passport be changed at a later date?

Does a Draconic Bloodline sorcerer's doubled proficiency bonus for Charisma checks against dragons apply to all dragon types or only the chosen one?

How do I deal with an erroneously large refund?

Getting AggregateResult variables from Execute Anonymous Window

What's parked in Mil Moscow helicopter plant?

Co-worker works way more than he should

What is /etc/mtab in Linux?

What does the black goddess statue do and what is it?

When does Bran Stark remember Jamie pushing him?

Coin Game with infinite paradox

Israeli soda type drink

How would you suggest I follow up with coworkers about our deadline that's today?

Will I be more secure with my own router behind my ISP's router?

Suing a Police Officer Instead of the Police Department

Is there a verb for listening stealthily?

What is the evidence that custom checks in Northern Ireland are going to result in violence?

How long can a nation maintain a technological edge over the rest of the world?



classification labels in headers and footers



Unicorn Meta Zoo #1: Why another podcast?
Announcing the arrival of Valued Associate #679: Cesar ManaraTest if a paragraph has a page break in it?Content Aware Headers and Footers?Suppress headers and footers for complete chapterHeaders and footers for listing environment?Problem with headers, footersHeaders and FootersContent Aware Headers and Footers?Customize headers and footersProblem headers/footers and biblatexCustom Headers And Footers Not AppearingGet Headers & Footers into Cornerstitlesec footers and headers












4















I'm trying to write Latex documents that will automatically satisfy government requirements for labeling certain classes of information:

- Each paragraph starts with a label indicating its importance.

- The header and footer of each page include a label indicating the
most important paragraph on that page (even if it started on the
previous page).



This is the closest I have come:



documentclass[12pt]{report}
usepackage{fancyhdr}
usepackage{ifthen}
usepackage{afterpage}
usepackage{color}
usepackage{lipsum}

setlengthparskip{.6baselineskip}
setlengthparindent{0pt}
setlengthheadheight{15pt}
setlengthtextheight{21baselineskip}
newcommandpageimport{TRIVIAL}
newcommandparaimport{TRIVIAL}

pagestyle{fancy}
lhead{}chead{leftmark}rhead{}
lfoot{}cfoot{leftmark}rfoot{thepage}

newcommand{IMP}[1]{renewcommandparaimport{IMPORTANT}
renewcommandpageimport{IMPORTANT}
markboth{pageimport}{paraimport}
afterpage{renewcommandpageimport{protectparaimport}markboth{protectparaimport}{}}
textcolor{red}{(I) #1}renewcommandparaimport{TRIVIAL}}

newcommand{TRI}[1]{renewcommandparaimport{TRIVIAL}
markboth{pageimport}{paraimport}
afterpage{renewcommandpageimport{protectparaimport}markboth{protectparaimport}{}}
(U) #1renewcommandparaimport{TRIVIAL}}

begin{document}
immediatetypeout{a. pageimport = pageimportspace paraimport = paraimport}
TRI{lipsum[1]}
TRI{lipsum[2]}
TRI{lipsum[3]}
immediatetypeout{b. pageimport = pageimportspace paraimport = paraimport}
IMP{lipsum[4]}
immediatetypeout{c. pageimport = pageimportspace paraimport = paraimport}
TRI{lipsum[5]}
TRI{lipsum[6]}
TRI{lipsum[7]}
TRI{lipsum[8]}
immediatetypeout{d. pageimport = pageimportspace paraimport = paraimport}
IMP{lipsum[9]}
immediatetypeout{e. pageimport = pageimportspace paraimport = paraimport}
TRI{lipsum[10]}
TRI{lipsum[11]}
TRI{lipsum[12]}
end{document}


(I've changed the labels here to avoid causing needless alarm. For
convenience, I have also set the "important" text in red.) My idea is
to keep the "importance" of each paragraph in paraimport. That gets
reset at the end of each paragraph. The header and footer get their
labels from pageimport, which records the highest importance on the
current page. At the end of each page, pageimport gets reset to the
value of paraimport.



This document has one "important" paragraph on page 2, and another
that starts on page 4 and ends on page 5. All the paragraphs are
correctly labeled. The first two pages have the right labels, but
pages 3 and 6 should be marked "trivial". The tracing statements
before and after each "important" paragraph show that pageimport is
not getting reset at the pagebreaks.



I suspect I'm moving something fragile, but rewriting the afterpage
commands as



afterpage{renewcommandpageimport{protectparaimport}markboth{protectparaimport}{}}


makes no difference.



I've seen secret.sty, but it's attacking a different problem. I have
not been able to adapt it for page marking.



I'd appreciate any suggestions.










share|improve this question























  • Welcome to TeX.SX! I think,afterpage is not sufficient here. In my impression there must be check about the last 'state' (TRIVIAL/IMPORTANT)

    – user31729
    Apr 16 '16 at 14:25


















4















I'm trying to write Latex documents that will automatically satisfy government requirements for labeling certain classes of information:

- Each paragraph starts with a label indicating its importance.

- The header and footer of each page include a label indicating the
most important paragraph on that page (even if it started on the
previous page).



This is the closest I have come:



documentclass[12pt]{report}
usepackage{fancyhdr}
usepackage{ifthen}
usepackage{afterpage}
usepackage{color}
usepackage{lipsum}

setlengthparskip{.6baselineskip}
setlengthparindent{0pt}
setlengthheadheight{15pt}
setlengthtextheight{21baselineskip}
newcommandpageimport{TRIVIAL}
newcommandparaimport{TRIVIAL}

pagestyle{fancy}
lhead{}chead{leftmark}rhead{}
lfoot{}cfoot{leftmark}rfoot{thepage}

newcommand{IMP}[1]{renewcommandparaimport{IMPORTANT}
renewcommandpageimport{IMPORTANT}
markboth{pageimport}{paraimport}
afterpage{renewcommandpageimport{protectparaimport}markboth{protectparaimport}{}}
textcolor{red}{(I) #1}renewcommandparaimport{TRIVIAL}}

newcommand{TRI}[1]{renewcommandparaimport{TRIVIAL}
markboth{pageimport}{paraimport}
afterpage{renewcommandpageimport{protectparaimport}markboth{protectparaimport}{}}
(U) #1renewcommandparaimport{TRIVIAL}}

begin{document}
immediatetypeout{a. pageimport = pageimportspace paraimport = paraimport}
TRI{lipsum[1]}
TRI{lipsum[2]}
TRI{lipsum[3]}
immediatetypeout{b. pageimport = pageimportspace paraimport = paraimport}
IMP{lipsum[4]}
immediatetypeout{c. pageimport = pageimportspace paraimport = paraimport}
TRI{lipsum[5]}
TRI{lipsum[6]}
TRI{lipsum[7]}
TRI{lipsum[8]}
immediatetypeout{d. pageimport = pageimportspace paraimport = paraimport}
IMP{lipsum[9]}
immediatetypeout{e. pageimport = pageimportspace paraimport = paraimport}
TRI{lipsum[10]}
TRI{lipsum[11]}
TRI{lipsum[12]}
end{document}


(I've changed the labels here to avoid causing needless alarm. For
convenience, I have also set the "important" text in red.) My idea is
to keep the "importance" of each paragraph in paraimport. That gets
reset at the end of each paragraph. The header and footer get their
labels from pageimport, which records the highest importance on the
current page. At the end of each page, pageimport gets reset to the
value of paraimport.



This document has one "important" paragraph on page 2, and another
that starts on page 4 and ends on page 5. All the paragraphs are
correctly labeled. The first two pages have the right labels, but
pages 3 and 6 should be marked "trivial". The tracing statements
before and after each "important" paragraph show that pageimport is
not getting reset at the pagebreaks.



I suspect I'm moving something fragile, but rewriting the afterpage
commands as



afterpage{renewcommandpageimport{protectparaimport}markboth{protectparaimport}{}}


makes no difference.



I've seen secret.sty, but it's attacking a different problem. I have
not been able to adapt it for page marking.



I'd appreciate any suggestions.










share|improve this question























  • Welcome to TeX.SX! I think,afterpage is not sufficient here. In my impression there must be check about the last 'state' (TRIVIAL/IMPORTANT)

    – user31729
    Apr 16 '16 at 14:25
















4












4








4








I'm trying to write Latex documents that will automatically satisfy government requirements for labeling certain classes of information:

- Each paragraph starts with a label indicating its importance.

- The header and footer of each page include a label indicating the
most important paragraph on that page (even if it started on the
previous page).



This is the closest I have come:



documentclass[12pt]{report}
usepackage{fancyhdr}
usepackage{ifthen}
usepackage{afterpage}
usepackage{color}
usepackage{lipsum}

setlengthparskip{.6baselineskip}
setlengthparindent{0pt}
setlengthheadheight{15pt}
setlengthtextheight{21baselineskip}
newcommandpageimport{TRIVIAL}
newcommandparaimport{TRIVIAL}

pagestyle{fancy}
lhead{}chead{leftmark}rhead{}
lfoot{}cfoot{leftmark}rfoot{thepage}

newcommand{IMP}[1]{renewcommandparaimport{IMPORTANT}
renewcommandpageimport{IMPORTANT}
markboth{pageimport}{paraimport}
afterpage{renewcommandpageimport{protectparaimport}markboth{protectparaimport}{}}
textcolor{red}{(I) #1}renewcommandparaimport{TRIVIAL}}

newcommand{TRI}[1]{renewcommandparaimport{TRIVIAL}
markboth{pageimport}{paraimport}
afterpage{renewcommandpageimport{protectparaimport}markboth{protectparaimport}{}}
(U) #1renewcommandparaimport{TRIVIAL}}

begin{document}
immediatetypeout{a. pageimport = pageimportspace paraimport = paraimport}
TRI{lipsum[1]}
TRI{lipsum[2]}
TRI{lipsum[3]}
immediatetypeout{b. pageimport = pageimportspace paraimport = paraimport}
IMP{lipsum[4]}
immediatetypeout{c. pageimport = pageimportspace paraimport = paraimport}
TRI{lipsum[5]}
TRI{lipsum[6]}
TRI{lipsum[7]}
TRI{lipsum[8]}
immediatetypeout{d. pageimport = pageimportspace paraimport = paraimport}
IMP{lipsum[9]}
immediatetypeout{e. pageimport = pageimportspace paraimport = paraimport}
TRI{lipsum[10]}
TRI{lipsum[11]}
TRI{lipsum[12]}
end{document}


(I've changed the labels here to avoid causing needless alarm. For
convenience, I have also set the "important" text in red.) My idea is
to keep the "importance" of each paragraph in paraimport. That gets
reset at the end of each paragraph. The header and footer get their
labels from pageimport, which records the highest importance on the
current page. At the end of each page, pageimport gets reset to the
value of paraimport.



This document has one "important" paragraph on page 2, and another
that starts on page 4 and ends on page 5. All the paragraphs are
correctly labeled. The first two pages have the right labels, but
pages 3 and 6 should be marked "trivial". The tracing statements
before and after each "important" paragraph show that pageimport is
not getting reset at the pagebreaks.



I suspect I'm moving something fragile, but rewriting the afterpage
commands as



afterpage{renewcommandpageimport{protectparaimport}markboth{protectparaimport}{}}


makes no difference.



I've seen secret.sty, but it's attacking a different problem. I have
not been able to adapt it for page marking.



I'd appreciate any suggestions.










share|improve this question














I'm trying to write Latex documents that will automatically satisfy government requirements for labeling certain classes of information:

- Each paragraph starts with a label indicating its importance.

- The header and footer of each page include a label indicating the
most important paragraph on that page (even if it started on the
previous page).



This is the closest I have come:



documentclass[12pt]{report}
usepackage{fancyhdr}
usepackage{ifthen}
usepackage{afterpage}
usepackage{color}
usepackage{lipsum}

setlengthparskip{.6baselineskip}
setlengthparindent{0pt}
setlengthheadheight{15pt}
setlengthtextheight{21baselineskip}
newcommandpageimport{TRIVIAL}
newcommandparaimport{TRIVIAL}

pagestyle{fancy}
lhead{}chead{leftmark}rhead{}
lfoot{}cfoot{leftmark}rfoot{thepage}

newcommand{IMP}[1]{renewcommandparaimport{IMPORTANT}
renewcommandpageimport{IMPORTANT}
markboth{pageimport}{paraimport}
afterpage{renewcommandpageimport{protectparaimport}markboth{protectparaimport}{}}
textcolor{red}{(I) #1}renewcommandparaimport{TRIVIAL}}

newcommand{TRI}[1]{renewcommandparaimport{TRIVIAL}
markboth{pageimport}{paraimport}
afterpage{renewcommandpageimport{protectparaimport}markboth{protectparaimport}{}}
(U) #1renewcommandparaimport{TRIVIAL}}

begin{document}
immediatetypeout{a. pageimport = pageimportspace paraimport = paraimport}
TRI{lipsum[1]}
TRI{lipsum[2]}
TRI{lipsum[3]}
immediatetypeout{b. pageimport = pageimportspace paraimport = paraimport}
IMP{lipsum[4]}
immediatetypeout{c. pageimport = pageimportspace paraimport = paraimport}
TRI{lipsum[5]}
TRI{lipsum[6]}
TRI{lipsum[7]}
TRI{lipsum[8]}
immediatetypeout{d. pageimport = pageimportspace paraimport = paraimport}
IMP{lipsum[9]}
immediatetypeout{e. pageimport = pageimportspace paraimport = paraimport}
TRI{lipsum[10]}
TRI{lipsum[11]}
TRI{lipsum[12]}
end{document}


(I've changed the labels here to avoid causing needless alarm. For
convenience, I have also set the "important" text in red.) My idea is
to keep the "importance" of each paragraph in paraimport. That gets
reset at the end of each paragraph. The header and footer get their
labels from pageimport, which records the highest importance on the
current page. At the end of each page, pageimport gets reset to the
value of paraimport.



This document has one "important" paragraph on page 2, and another
that starts on page 4 and ends on page 5. All the paragraphs are
correctly labeled. The first two pages have the right labels, but
pages 3 and 6 should be marked "trivial". The tracing statements
before and after each "important" paragraph show that pageimport is
not getting reset at the pagebreaks.



I suspect I'm moving something fragile, but rewriting the afterpage
commands as



afterpage{renewcommandpageimport{protectparaimport}markboth{protectparaimport}{}}


makes no difference.



I've seen secret.sty, but it's attacking a different problem. I have
not been able to adapt it for page marking.



I'd appreciate any suggestions.







header-footer page-breaking






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Apr 16 '16 at 14:09









Jim Van ZandtJim Van Zandt

464




464













  • Welcome to TeX.SX! I think,afterpage is not sufficient here. In my impression there must be check about the last 'state' (TRIVIAL/IMPORTANT)

    – user31729
    Apr 16 '16 at 14:25





















  • Welcome to TeX.SX! I think,afterpage is not sufficient here. In my impression there must be check about the last 'state' (TRIVIAL/IMPORTANT)

    – user31729
    Apr 16 '16 at 14:25



















Welcome to TeX.SX! I think,afterpage is not sufficient here. In my impression there must be check about the last 'state' (TRIVIAL/IMPORTANT)

– user31729
Apr 16 '16 at 14:25







Welcome to TeX.SX! I think,afterpage is not sufficient here. In my impression there must be check about the last 'state' (TRIVIAL/IMPORTANT)

– user31729
Apr 16 '16 at 14:25












3 Answers
3






active

oldest

votes


















1














Here is a solution.



The key point is to reset left and right marks



afterpage{%
renewcommandparaimport{TRIVIAL}%
markboth{paraimport}{paraimport}


Note We need only one command paraimport



Update the idea is to redefine parimport and markboth inside paragraphs i.e. just after (I).



Updated MWE



documentclass[12pt]{report}
usepackage{fancyhdr}
usepackage{afterpage}
usepackage{color}
usepackage{lipsum}

setlengthparskip{.6baselineskip}
setlengthparindent{0pt}
setlengthheadheight{15pt}
setlengthtextheight{21baselineskip}


pagestyle{fancy}
lhead{}chead{leftmark}rhead{}
lfoot{}cfoot{leftmark}rfoot{thepage}

newcommandparaimport{TRIVIAL}
markboth{paraimport}{paraimport}

newcommand{IMP}[1]{%
textcolor{red}{(I)
renewcommandparaimport{IMPORTANT}%
markboth{paraimport}{paraimport}%
#1}%
afterpage{%
renewcommandparaimport{TRIVIAL}%
markboth{paraimport}{paraimport}}%
}

newcommand{TRI}[1]{(U) #1}

begin{document}
TRI{lipsum[1]}
TRI{lipsum[2]}
TRI{lipsum[3]}
IMP{lipsum[4]}
TRI{lipsum[5]}
TRI{lipsum[6]}
TRI{lipsum[7]}
TRI{lipsum[8]}
IMP{lipsum[9]}
TRI{lipsum[10]}
TRI{lipsum[11]}
TRI{lipsum[12]}
end{document}





share|improve this answer


























  • Thanks - that does fix the MWE. But I'd really like to know why it works.

    – Jim Van Zandt
    Apr 17 '16 at 21:54











  • Unfortunately there is still a flaw. My MWE included cases where the pagebreak occurred within a "trivial" paragraph or within an "important" one. If I shorten the pages by one line using "setlengthtextheight{20baselineskip}", then a pagebreaks occur just before an "important" paragraph, which triggers a bug: If a page starts with an "important" paragraph, then the previous page is also marked "important". Apparently by the time TeX decides to insert the pagebreak, paraimport and leftmark have already been set. Any ideas how to handle that case?

    – Jim Van Zandt
    Apr 17 '16 at 22:24











  • I just found another similar topic "Content Aware Headers and Footers" at tex.stackexchange.com/questions/97891/…. Unfortunately the solution by @Eric has the same flaw: If a page starts with a higher classification than anything on the previous page, the previous page gets marked with the higher classification.

    – Jim Van Zandt
    Apr 17 '16 at 23:08













  • I update the answer fixing the bug. I will try to explain how later.

    – touhami
    Apr 18 '16 at 5:56











  • I think I see how your fix works. By waiting until a few characters in the new paragraph have been scanned, we ensure that TeX has made its pagebreak decisions before we reset the headers and footers. Thanks!

    – Jim Van Zandt
    Apr 18 '16 at 10:26



















0














It seems as though the most complicated part of this problem is the case when a paragraph continues through a page break. Perhaps the easiest thing to do is to prevent paragraphs from doing so:



widowpenalties 1 10000
raggedbottom





share|improve this answer































    0














    The question is a bit old, but it still comes up high on a web search. I was trying to adapt the solution for multiple importance levels and came across this answer to check if a paragraph spans a page break. My thought solution is to set a counter and increment the counter if a paragraph has a higher importance level than the current paragraph. If the last paragraph on the page spans the page break, I set the page level on the next page to the current level and repeat the process. What I came up with is



    documentclass{article}

    usepackage{afterpage}
    usepackage{lipsum}
    usepackage{fancyhdr}
    pagestyle{fancy}
    fancyhf{}

    newcounter{pagelevel}

    usepackage{atbegshi}
    usepackage{zref-user}
    usepackage{zref-abspage}

    makeatletter
    newcounter{clscnt}
    newenvironment{markingenv}[1]{%
    stepcounter{clscnt}%
    zlabel{markingenv-begin-theclscnt}%
    (#1 --- thepagelevel)
    ifnum #1 > thepagelevel%
    setcounter{pagelevel}{#1}%
    chead{Level thepagelevel}%
    fi%
    }{%
    zlabel{markingenv-end-theclscnt}%
    ifnumzref@extract{markingenv-begin-theclscnt}{abspage}
    =zref@extract{markingenv-end-theclscnt}{abspage}
    AtBeginShipoutNext{setcounter{pagelevel}{thepagelevel}}%
    else
    AtBeginShipoutNext{setcounter{pagelevel}{0}}%
    fi
    }
    makeatother

    newcommand{marking}[2]{%
    begin{markingenv}{#1}%
    #2
    end{markingenv}%
    }

    newcommand{VI}[1]{marking{3}{(V) #1}}
    newcommand{IMP}[1]{marking{2}{(I) #1}}
    newcommand{TRI}[1]{marking{1}{(U) #1}}

    begin{document}
    TRI{lipsum[1]par}
    TRI{lipsum[2]par}
    TRI{lipsum[3]par}
    IMP{lipsum[4]par}
    TRI{lipsum[5]par}
    TRI{lipsum[6]par}
    TRI{lipsum[7]par}
    TRI{lipsum[8]par}
    IMP{lipsum[9]par}
    TRI{lipsum[10]par}
    TRI{lipsum[11]par}
    TRI{lipsum[12]par}
    TRI{lipsum[13]par}
    TRI{lipsum[14]par}
    TRI{lipsum[15]par}
    VI{lipsum[16]par}
    IMP{lipsum[17]par}
    TRI{lipsum[18]par}
    TRI{lipsum[19]par}
    TRI{lipsum[20]par}
    TRI{lipsum[21]par}
    TRI{lipsum[22]par}
    TRI{lipsum[23]par}
    TRI{lipsum[24]par}
    TRI{lipsum[25]par}
    TRI{lipsum[26]par}
    TRI{lipsum[27]par}
    TRI{lipsum[28]par}
    TRI{lipsum[29]par}
    end{document}


    I modified the example to explicitly show the page level and paragraph level. Note that pages 3 and 4 correctly have the heading set to level 3 and the heading is reset to 1 on pages 5 and 6.






    share|improve this answer
























      Your Answer








      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "85"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f304615%2fclassification-labels-in-headers-and-footers%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      Here is a solution.



      The key point is to reset left and right marks



      afterpage{%
      renewcommandparaimport{TRIVIAL}%
      markboth{paraimport}{paraimport}


      Note We need only one command paraimport



      Update the idea is to redefine parimport and markboth inside paragraphs i.e. just after (I).



      Updated MWE



      documentclass[12pt]{report}
      usepackage{fancyhdr}
      usepackage{afterpage}
      usepackage{color}
      usepackage{lipsum}

      setlengthparskip{.6baselineskip}
      setlengthparindent{0pt}
      setlengthheadheight{15pt}
      setlengthtextheight{21baselineskip}


      pagestyle{fancy}
      lhead{}chead{leftmark}rhead{}
      lfoot{}cfoot{leftmark}rfoot{thepage}

      newcommandparaimport{TRIVIAL}
      markboth{paraimport}{paraimport}

      newcommand{IMP}[1]{%
      textcolor{red}{(I)
      renewcommandparaimport{IMPORTANT}%
      markboth{paraimport}{paraimport}%
      #1}%
      afterpage{%
      renewcommandparaimport{TRIVIAL}%
      markboth{paraimport}{paraimport}}%
      }

      newcommand{TRI}[1]{(U) #1}

      begin{document}
      TRI{lipsum[1]}
      TRI{lipsum[2]}
      TRI{lipsum[3]}
      IMP{lipsum[4]}
      TRI{lipsum[5]}
      TRI{lipsum[6]}
      TRI{lipsum[7]}
      TRI{lipsum[8]}
      IMP{lipsum[9]}
      TRI{lipsum[10]}
      TRI{lipsum[11]}
      TRI{lipsum[12]}
      end{document}





      share|improve this answer


























      • Thanks - that does fix the MWE. But I'd really like to know why it works.

        – Jim Van Zandt
        Apr 17 '16 at 21:54











      • Unfortunately there is still a flaw. My MWE included cases where the pagebreak occurred within a "trivial" paragraph or within an "important" one. If I shorten the pages by one line using "setlengthtextheight{20baselineskip}", then a pagebreaks occur just before an "important" paragraph, which triggers a bug: If a page starts with an "important" paragraph, then the previous page is also marked "important". Apparently by the time TeX decides to insert the pagebreak, paraimport and leftmark have already been set. Any ideas how to handle that case?

        – Jim Van Zandt
        Apr 17 '16 at 22:24











      • I just found another similar topic "Content Aware Headers and Footers" at tex.stackexchange.com/questions/97891/…. Unfortunately the solution by @Eric has the same flaw: If a page starts with a higher classification than anything on the previous page, the previous page gets marked with the higher classification.

        – Jim Van Zandt
        Apr 17 '16 at 23:08













      • I update the answer fixing the bug. I will try to explain how later.

        – touhami
        Apr 18 '16 at 5:56











      • I think I see how your fix works. By waiting until a few characters in the new paragraph have been scanned, we ensure that TeX has made its pagebreak decisions before we reset the headers and footers. Thanks!

        – Jim Van Zandt
        Apr 18 '16 at 10:26
















      1














      Here is a solution.



      The key point is to reset left and right marks



      afterpage{%
      renewcommandparaimport{TRIVIAL}%
      markboth{paraimport}{paraimport}


      Note We need only one command paraimport



      Update the idea is to redefine parimport and markboth inside paragraphs i.e. just after (I).



      Updated MWE



      documentclass[12pt]{report}
      usepackage{fancyhdr}
      usepackage{afterpage}
      usepackage{color}
      usepackage{lipsum}

      setlengthparskip{.6baselineskip}
      setlengthparindent{0pt}
      setlengthheadheight{15pt}
      setlengthtextheight{21baselineskip}


      pagestyle{fancy}
      lhead{}chead{leftmark}rhead{}
      lfoot{}cfoot{leftmark}rfoot{thepage}

      newcommandparaimport{TRIVIAL}
      markboth{paraimport}{paraimport}

      newcommand{IMP}[1]{%
      textcolor{red}{(I)
      renewcommandparaimport{IMPORTANT}%
      markboth{paraimport}{paraimport}%
      #1}%
      afterpage{%
      renewcommandparaimport{TRIVIAL}%
      markboth{paraimport}{paraimport}}%
      }

      newcommand{TRI}[1]{(U) #1}

      begin{document}
      TRI{lipsum[1]}
      TRI{lipsum[2]}
      TRI{lipsum[3]}
      IMP{lipsum[4]}
      TRI{lipsum[5]}
      TRI{lipsum[6]}
      TRI{lipsum[7]}
      TRI{lipsum[8]}
      IMP{lipsum[9]}
      TRI{lipsum[10]}
      TRI{lipsum[11]}
      TRI{lipsum[12]}
      end{document}





      share|improve this answer


























      • Thanks - that does fix the MWE. But I'd really like to know why it works.

        – Jim Van Zandt
        Apr 17 '16 at 21:54











      • Unfortunately there is still a flaw. My MWE included cases where the pagebreak occurred within a "trivial" paragraph or within an "important" one. If I shorten the pages by one line using "setlengthtextheight{20baselineskip}", then a pagebreaks occur just before an "important" paragraph, which triggers a bug: If a page starts with an "important" paragraph, then the previous page is also marked "important". Apparently by the time TeX decides to insert the pagebreak, paraimport and leftmark have already been set. Any ideas how to handle that case?

        – Jim Van Zandt
        Apr 17 '16 at 22:24











      • I just found another similar topic "Content Aware Headers and Footers" at tex.stackexchange.com/questions/97891/…. Unfortunately the solution by @Eric has the same flaw: If a page starts with a higher classification than anything on the previous page, the previous page gets marked with the higher classification.

        – Jim Van Zandt
        Apr 17 '16 at 23:08













      • I update the answer fixing the bug. I will try to explain how later.

        – touhami
        Apr 18 '16 at 5:56











      • I think I see how your fix works. By waiting until a few characters in the new paragraph have been scanned, we ensure that TeX has made its pagebreak decisions before we reset the headers and footers. Thanks!

        – Jim Van Zandt
        Apr 18 '16 at 10:26














      1












      1








      1







      Here is a solution.



      The key point is to reset left and right marks



      afterpage{%
      renewcommandparaimport{TRIVIAL}%
      markboth{paraimport}{paraimport}


      Note We need only one command paraimport



      Update the idea is to redefine parimport and markboth inside paragraphs i.e. just after (I).



      Updated MWE



      documentclass[12pt]{report}
      usepackage{fancyhdr}
      usepackage{afterpage}
      usepackage{color}
      usepackage{lipsum}

      setlengthparskip{.6baselineskip}
      setlengthparindent{0pt}
      setlengthheadheight{15pt}
      setlengthtextheight{21baselineskip}


      pagestyle{fancy}
      lhead{}chead{leftmark}rhead{}
      lfoot{}cfoot{leftmark}rfoot{thepage}

      newcommandparaimport{TRIVIAL}
      markboth{paraimport}{paraimport}

      newcommand{IMP}[1]{%
      textcolor{red}{(I)
      renewcommandparaimport{IMPORTANT}%
      markboth{paraimport}{paraimport}%
      #1}%
      afterpage{%
      renewcommandparaimport{TRIVIAL}%
      markboth{paraimport}{paraimport}}%
      }

      newcommand{TRI}[1]{(U) #1}

      begin{document}
      TRI{lipsum[1]}
      TRI{lipsum[2]}
      TRI{lipsum[3]}
      IMP{lipsum[4]}
      TRI{lipsum[5]}
      TRI{lipsum[6]}
      TRI{lipsum[7]}
      TRI{lipsum[8]}
      IMP{lipsum[9]}
      TRI{lipsum[10]}
      TRI{lipsum[11]}
      TRI{lipsum[12]}
      end{document}





      share|improve this answer















      Here is a solution.



      The key point is to reset left and right marks



      afterpage{%
      renewcommandparaimport{TRIVIAL}%
      markboth{paraimport}{paraimport}


      Note We need only one command paraimport



      Update the idea is to redefine parimport and markboth inside paragraphs i.e. just after (I).



      Updated MWE



      documentclass[12pt]{report}
      usepackage{fancyhdr}
      usepackage{afterpage}
      usepackage{color}
      usepackage{lipsum}

      setlengthparskip{.6baselineskip}
      setlengthparindent{0pt}
      setlengthheadheight{15pt}
      setlengthtextheight{21baselineskip}


      pagestyle{fancy}
      lhead{}chead{leftmark}rhead{}
      lfoot{}cfoot{leftmark}rfoot{thepage}

      newcommandparaimport{TRIVIAL}
      markboth{paraimport}{paraimport}

      newcommand{IMP}[1]{%
      textcolor{red}{(I)
      renewcommandparaimport{IMPORTANT}%
      markboth{paraimport}{paraimport}%
      #1}%
      afterpage{%
      renewcommandparaimport{TRIVIAL}%
      markboth{paraimport}{paraimport}}%
      }

      newcommand{TRI}[1]{(U) #1}

      begin{document}
      TRI{lipsum[1]}
      TRI{lipsum[2]}
      TRI{lipsum[3]}
      IMP{lipsum[4]}
      TRI{lipsum[5]}
      TRI{lipsum[6]}
      TRI{lipsum[7]}
      TRI{lipsum[8]}
      IMP{lipsum[9]}
      TRI{lipsum[10]}
      TRI{lipsum[11]}
      TRI{lipsum[12]}
      end{document}






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Apr 18 '16 at 5:55

























      answered Apr 16 '16 at 18:03









      touhamitouhami

      17.1k21246




      17.1k21246













      • Thanks - that does fix the MWE. But I'd really like to know why it works.

        – Jim Van Zandt
        Apr 17 '16 at 21:54











      • Unfortunately there is still a flaw. My MWE included cases where the pagebreak occurred within a "trivial" paragraph or within an "important" one. If I shorten the pages by one line using "setlengthtextheight{20baselineskip}", then a pagebreaks occur just before an "important" paragraph, which triggers a bug: If a page starts with an "important" paragraph, then the previous page is also marked "important". Apparently by the time TeX decides to insert the pagebreak, paraimport and leftmark have already been set. Any ideas how to handle that case?

        – Jim Van Zandt
        Apr 17 '16 at 22:24











      • I just found another similar topic "Content Aware Headers and Footers" at tex.stackexchange.com/questions/97891/…. Unfortunately the solution by @Eric has the same flaw: If a page starts with a higher classification than anything on the previous page, the previous page gets marked with the higher classification.

        – Jim Van Zandt
        Apr 17 '16 at 23:08













      • I update the answer fixing the bug. I will try to explain how later.

        – touhami
        Apr 18 '16 at 5:56











      • I think I see how your fix works. By waiting until a few characters in the new paragraph have been scanned, we ensure that TeX has made its pagebreak decisions before we reset the headers and footers. Thanks!

        – Jim Van Zandt
        Apr 18 '16 at 10:26



















      • Thanks - that does fix the MWE. But I'd really like to know why it works.

        – Jim Van Zandt
        Apr 17 '16 at 21:54











      • Unfortunately there is still a flaw. My MWE included cases where the pagebreak occurred within a "trivial" paragraph or within an "important" one. If I shorten the pages by one line using "setlengthtextheight{20baselineskip}", then a pagebreaks occur just before an "important" paragraph, which triggers a bug: If a page starts with an "important" paragraph, then the previous page is also marked "important". Apparently by the time TeX decides to insert the pagebreak, paraimport and leftmark have already been set. Any ideas how to handle that case?

        – Jim Van Zandt
        Apr 17 '16 at 22:24











      • I just found another similar topic "Content Aware Headers and Footers" at tex.stackexchange.com/questions/97891/…. Unfortunately the solution by @Eric has the same flaw: If a page starts with a higher classification than anything on the previous page, the previous page gets marked with the higher classification.

        – Jim Van Zandt
        Apr 17 '16 at 23:08













      • I update the answer fixing the bug. I will try to explain how later.

        – touhami
        Apr 18 '16 at 5:56











      • I think I see how your fix works. By waiting until a few characters in the new paragraph have been scanned, we ensure that TeX has made its pagebreak decisions before we reset the headers and footers. Thanks!

        – Jim Van Zandt
        Apr 18 '16 at 10:26

















      Thanks - that does fix the MWE. But I'd really like to know why it works.

      – Jim Van Zandt
      Apr 17 '16 at 21:54





      Thanks - that does fix the MWE. But I'd really like to know why it works.

      – Jim Van Zandt
      Apr 17 '16 at 21:54













      Unfortunately there is still a flaw. My MWE included cases where the pagebreak occurred within a "trivial" paragraph or within an "important" one. If I shorten the pages by one line using "setlengthtextheight{20baselineskip}", then a pagebreaks occur just before an "important" paragraph, which triggers a bug: If a page starts with an "important" paragraph, then the previous page is also marked "important". Apparently by the time TeX decides to insert the pagebreak, paraimport and leftmark have already been set. Any ideas how to handle that case?

      – Jim Van Zandt
      Apr 17 '16 at 22:24





      Unfortunately there is still a flaw. My MWE included cases where the pagebreak occurred within a "trivial" paragraph or within an "important" one. If I shorten the pages by one line using "setlengthtextheight{20baselineskip}", then a pagebreaks occur just before an "important" paragraph, which triggers a bug: If a page starts with an "important" paragraph, then the previous page is also marked "important". Apparently by the time TeX decides to insert the pagebreak, paraimport and leftmark have already been set. Any ideas how to handle that case?

      – Jim Van Zandt
      Apr 17 '16 at 22:24













      I just found another similar topic "Content Aware Headers and Footers" at tex.stackexchange.com/questions/97891/…. Unfortunately the solution by @Eric has the same flaw: If a page starts with a higher classification than anything on the previous page, the previous page gets marked with the higher classification.

      – Jim Van Zandt
      Apr 17 '16 at 23:08







      I just found another similar topic "Content Aware Headers and Footers" at tex.stackexchange.com/questions/97891/…. Unfortunately the solution by @Eric has the same flaw: If a page starts with a higher classification than anything on the previous page, the previous page gets marked with the higher classification.

      – Jim Van Zandt
      Apr 17 '16 at 23:08















      I update the answer fixing the bug. I will try to explain how later.

      – touhami
      Apr 18 '16 at 5:56





      I update the answer fixing the bug. I will try to explain how later.

      – touhami
      Apr 18 '16 at 5:56













      I think I see how your fix works. By waiting until a few characters in the new paragraph have been scanned, we ensure that TeX has made its pagebreak decisions before we reset the headers and footers. Thanks!

      – Jim Van Zandt
      Apr 18 '16 at 10:26





      I think I see how your fix works. By waiting until a few characters in the new paragraph have been scanned, we ensure that TeX has made its pagebreak decisions before we reset the headers and footers. Thanks!

      – Jim Van Zandt
      Apr 18 '16 at 10:26











      0














      It seems as though the most complicated part of this problem is the case when a paragraph continues through a page break. Perhaps the easiest thing to do is to prevent paragraphs from doing so:



      widowpenalties 1 10000
      raggedbottom





      share|improve this answer




























        0














        It seems as though the most complicated part of this problem is the case when a paragraph continues through a page break. Perhaps the easiest thing to do is to prevent paragraphs from doing so:



        widowpenalties 1 10000
        raggedbottom





        share|improve this answer


























          0












          0








          0







          It seems as though the most complicated part of this problem is the case when a paragraph continues through a page break. Perhaps the easiest thing to do is to prevent paragraphs from doing so:



          widowpenalties 1 10000
          raggedbottom





          share|improve this answer













          It seems as though the most complicated part of this problem is the case when a paragraph continues through a page break. Perhaps the easiest thing to do is to prevent paragraphs from doing so:



          widowpenalties 1 10000
          raggedbottom






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jul 14 '16 at 16:20









          Austin A.Austin A.

          1397




          1397























              0














              The question is a bit old, but it still comes up high on a web search. I was trying to adapt the solution for multiple importance levels and came across this answer to check if a paragraph spans a page break. My thought solution is to set a counter and increment the counter if a paragraph has a higher importance level than the current paragraph. If the last paragraph on the page spans the page break, I set the page level on the next page to the current level and repeat the process. What I came up with is



              documentclass{article}

              usepackage{afterpage}
              usepackage{lipsum}
              usepackage{fancyhdr}
              pagestyle{fancy}
              fancyhf{}

              newcounter{pagelevel}

              usepackage{atbegshi}
              usepackage{zref-user}
              usepackage{zref-abspage}

              makeatletter
              newcounter{clscnt}
              newenvironment{markingenv}[1]{%
              stepcounter{clscnt}%
              zlabel{markingenv-begin-theclscnt}%
              (#1 --- thepagelevel)
              ifnum #1 > thepagelevel%
              setcounter{pagelevel}{#1}%
              chead{Level thepagelevel}%
              fi%
              }{%
              zlabel{markingenv-end-theclscnt}%
              ifnumzref@extract{markingenv-begin-theclscnt}{abspage}
              =zref@extract{markingenv-end-theclscnt}{abspage}
              AtBeginShipoutNext{setcounter{pagelevel}{thepagelevel}}%
              else
              AtBeginShipoutNext{setcounter{pagelevel}{0}}%
              fi
              }
              makeatother

              newcommand{marking}[2]{%
              begin{markingenv}{#1}%
              #2
              end{markingenv}%
              }

              newcommand{VI}[1]{marking{3}{(V) #1}}
              newcommand{IMP}[1]{marking{2}{(I) #1}}
              newcommand{TRI}[1]{marking{1}{(U) #1}}

              begin{document}
              TRI{lipsum[1]par}
              TRI{lipsum[2]par}
              TRI{lipsum[3]par}
              IMP{lipsum[4]par}
              TRI{lipsum[5]par}
              TRI{lipsum[6]par}
              TRI{lipsum[7]par}
              TRI{lipsum[8]par}
              IMP{lipsum[9]par}
              TRI{lipsum[10]par}
              TRI{lipsum[11]par}
              TRI{lipsum[12]par}
              TRI{lipsum[13]par}
              TRI{lipsum[14]par}
              TRI{lipsum[15]par}
              VI{lipsum[16]par}
              IMP{lipsum[17]par}
              TRI{lipsum[18]par}
              TRI{lipsum[19]par}
              TRI{lipsum[20]par}
              TRI{lipsum[21]par}
              TRI{lipsum[22]par}
              TRI{lipsum[23]par}
              TRI{lipsum[24]par}
              TRI{lipsum[25]par}
              TRI{lipsum[26]par}
              TRI{lipsum[27]par}
              TRI{lipsum[28]par}
              TRI{lipsum[29]par}
              end{document}


              I modified the example to explicitly show the page level and paragraph level. Note that pages 3 and 4 correctly have the heading set to level 3 and the heading is reset to 1 on pages 5 and 6.






              share|improve this answer




























                0














                The question is a bit old, but it still comes up high on a web search. I was trying to adapt the solution for multiple importance levels and came across this answer to check if a paragraph spans a page break. My thought solution is to set a counter and increment the counter if a paragraph has a higher importance level than the current paragraph. If the last paragraph on the page spans the page break, I set the page level on the next page to the current level and repeat the process. What I came up with is



                documentclass{article}

                usepackage{afterpage}
                usepackage{lipsum}
                usepackage{fancyhdr}
                pagestyle{fancy}
                fancyhf{}

                newcounter{pagelevel}

                usepackage{atbegshi}
                usepackage{zref-user}
                usepackage{zref-abspage}

                makeatletter
                newcounter{clscnt}
                newenvironment{markingenv}[1]{%
                stepcounter{clscnt}%
                zlabel{markingenv-begin-theclscnt}%
                (#1 --- thepagelevel)
                ifnum #1 > thepagelevel%
                setcounter{pagelevel}{#1}%
                chead{Level thepagelevel}%
                fi%
                }{%
                zlabel{markingenv-end-theclscnt}%
                ifnumzref@extract{markingenv-begin-theclscnt}{abspage}
                =zref@extract{markingenv-end-theclscnt}{abspage}
                AtBeginShipoutNext{setcounter{pagelevel}{thepagelevel}}%
                else
                AtBeginShipoutNext{setcounter{pagelevel}{0}}%
                fi
                }
                makeatother

                newcommand{marking}[2]{%
                begin{markingenv}{#1}%
                #2
                end{markingenv}%
                }

                newcommand{VI}[1]{marking{3}{(V) #1}}
                newcommand{IMP}[1]{marking{2}{(I) #1}}
                newcommand{TRI}[1]{marking{1}{(U) #1}}

                begin{document}
                TRI{lipsum[1]par}
                TRI{lipsum[2]par}
                TRI{lipsum[3]par}
                IMP{lipsum[4]par}
                TRI{lipsum[5]par}
                TRI{lipsum[6]par}
                TRI{lipsum[7]par}
                TRI{lipsum[8]par}
                IMP{lipsum[9]par}
                TRI{lipsum[10]par}
                TRI{lipsum[11]par}
                TRI{lipsum[12]par}
                TRI{lipsum[13]par}
                TRI{lipsum[14]par}
                TRI{lipsum[15]par}
                VI{lipsum[16]par}
                IMP{lipsum[17]par}
                TRI{lipsum[18]par}
                TRI{lipsum[19]par}
                TRI{lipsum[20]par}
                TRI{lipsum[21]par}
                TRI{lipsum[22]par}
                TRI{lipsum[23]par}
                TRI{lipsum[24]par}
                TRI{lipsum[25]par}
                TRI{lipsum[26]par}
                TRI{lipsum[27]par}
                TRI{lipsum[28]par}
                TRI{lipsum[29]par}
                end{document}


                I modified the example to explicitly show the page level and paragraph level. Note that pages 3 and 4 correctly have the heading set to level 3 and the heading is reset to 1 on pages 5 and 6.






                share|improve this answer


























                  0












                  0








                  0







                  The question is a bit old, but it still comes up high on a web search. I was trying to adapt the solution for multiple importance levels and came across this answer to check if a paragraph spans a page break. My thought solution is to set a counter and increment the counter if a paragraph has a higher importance level than the current paragraph. If the last paragraph on the page spans the page break, I set the page level on the next page to the current level and repeat the process. What I came up with is



                  documentclass{article}

                  usepackage{afterpage}
                  usepackage{lipsum}
                  usepackage{fancyhdr}
                  pagestyle{fancy}
                  fancyhf{}

                  newcounter{pagelevel}

                  usepackage{atbegshi}
                  usepackage{zref-user}
                  usepackage{zref-abspage}

                  makeatletter
                  newcounter{clscnt}
                  newenvironment{markingenv}[1]{%
                  stepcounter{clscnt}%
                  zlabel{markingenv-begin-theclscnt}%
                  (#1 --- thepagelevel)
                  ifnum #1 > thepagelevel%
                  setcounter{pagelevel}{#1}%
                  chead{Level thepagelevel}%
                  fi%
                  }{%
                  zlabel{markingenv-end-theclscnt}%
                  ifnumzref@extract{markingenv-begin-theclscnt}{abspage}
                  =zref@extract{markingenv-end-theclscnt}{abspage}
                  AtBeginShipoutNext{setcounter{pagelevel}{thepagelevel}}%
                  else
                  AtBeginShipoutNext{setcounter{pagelevel}{0}}%
                  fi
                  }
                  makeatother

                  newcommand{marking}[2]{%
                  begin{markingenv}{#1}%
                  #2
                  end{markingenv}%
                  }

                  newcommand{VI}[1]{marking{3}{(V) #1}}
                  newcommand{IMP}[1]{marking{2}{(I) #1}}
                  newcommand{TRI}[1]{marking{1}{(U) #1}}

                  begin{document}
                  TRI{lipsum[1]par}
                  TRI{lipsum[2]par}
                  TRI{lipsum[3]par}
                  IMP{lipsum[4]par}
                  TRI{lipsum[5]par}
                  TRI{lipsum[6]par}
                  TRI{lipsum[7]par}
                  TRI{lipsum[8]par}
                  IMP{lipsum[9]par}
                  TRI{lipsum[10]par}
                  TRI{lipsum[11]par}
                  TRI{lipsum[12]par}
                  TRI{lipsum[13]par}
                  TRI{lipsum[14]par}
                  TRI{lipsum[15]par}
                  VI{lipsum[16]par}
                  IMP{lipsum[17]par}
                  TRI{lipsum[18]par}
                  TRI{lipsum[19]par}
                  TRI{lipsum[20]par}
                  TRI{lipsum[21]par}
                  TRI{lipsum[22]par}
                  TRI{lipsum[23]par}
                  TRI{lipsum[24]par}
                  TRI{lipsum[25]par}
                  TRI{lipsum[26]par}
                  TRI{lipsum[27]par}
                  TRI{lipsum[28]par}
                  TRI{lipsum[29]par}
                  end{document}


                  I modified the example to explicitly show the page level and paragraph level. Note that pages 3 and 4 correctly have the heading set to level 3 and the heading is reset to 1 on pages 5 and 6.






                  share|improve this answer













                  The question is a bit old, but it still comes up high on a web search. I was trying to adapt the solution for multiple importance levels and came across this answer to check if a paragraph spans a page break. My thought solution is to set a counter and increment the counter if a paragraph has a higher importance level than the current paragraph. If the last paragraph on the page spans the page break, I set the page level on the next page to the current level and repeat the process. What I came up with is



                  documentclass{article}

                  usepackage{afterpage}
                  usepackage{lipsum}
                  usepackage{fancyhdr}
                  pagestyle{fancy}
                  fancyhf{}

                  newcounter{pagelevel}

                  usepackage{atbegshi}
                  usepackage{zref-user}
                  usepackage{zref-abspage}

                  makeatletter
                  newcounter{clscnt}
                  newenvironment{markingenv}[1]{%
                  stepcounter{clscnt}%
                  zlabel{markingenv-begin-theclscnt}%
                  (#1 --- thepagelevel)
                  ifnum #1 > thepagelevel%
                  setcounter{pagelevel}{#1}%
                  chead{Level thepagelevel}%
                  fi%
                  }{%
                  zlabel{markingenv-end-theclscnt}%
                  ifnumzref@extract{markingenv-begin-theclscnt}{abspage}
                  =zref@extract{markingenv-end-theclscnt}{abspage}
                  AtBeginShipoutNext{setcounter{pagelevel}{thepagelevel}}%
                  else
                  AtBeginShipoutNext{setcounter{pagelevel}{0}}%
                  fi
                  }
                  makeatother

                  newcommand{marking}[2]{%
                  begin{markingenv}{#1}%
                  #2
                  end{markingenv}%
                  }

                  newcommand{VI}[1]{marking{3}{(V) #1}}
                  newcommand{IMP}[1]{marking{2}{(I) #1}}
                  newcommand{TRI}[1]{marking{1}{(U) #1}}

                  begin{document}
                  TRI{lipsum[1]par}
                  TRI{lipsum[2]par}
                  TRI{lipsum[3]par}
                  IMP{lipsum[4]par}
                  TRI{lipsum[5]par}
                  TRI{lipsum[6]par}
                  TRI{lipsum[7]par}
                  TRI{lipsum[8]par}
                  IMP{lipsum[9]par}
                  TRI{lipsum[10]par}
                  TRI{lipsum[11]par}
                  TRI{lipsum[12]par}
                  TRI{lipsum[13]par}
                  TRI{lipsum[14]par}
                  TRI{lipsum[15]par}
                  VI{lipsum[16]par}
                  IMP{lipsum[17]par}
                  TRI{lipsum[18]par}
                  TRI{lipsum[19]par}
                  TRI{lipsum[20]par}
                  TRI{lipsum[21]par}
                  TRI{lipsum[22]par}
                  TRI{lipsum[23]par}
                  TRI{lipsum[24]par}
                  TRI{lipsum[25]par}
                  TRI{lipsum[26]par}
                  TRI{lipsum[27]par}
                  TRI{lipsum[28]par}
                  TRI{lipsum[29]par}
                  end{document}


                  I modified the example to explicitly show the page level and paragraph level. Note that pages 3 and 4 correctly have the heading set to level 3 and the heading is reset to 1 on pages 5 and 6.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered 11 mins ago









                  Keith PrussingKeith Prussing

                  15817




                  15817






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f304615%2fclassification-labels-in-headers-and-footers%23new-answer', 'question_page');
                      }
                      );

                      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







                      Popular posts from this blog

                      Can't compile dgruyter and caption packagesLaTeX templates/packages for writing a patent specificationLatex...

                      Schneeberg (Smreczany) Bibliografia | Menu...

                      Hans Bellmer Spis treści Życiorys | Upamiętnienie | Przypisy | Bibliografia | Linki zewnętrzne |...