0

I am wasting days of my life rewriting rejected papers for other conferences with different page limits. Also it would be nice to extract parts for a website without a page limit.

Is there a way to automatically hide sentences or just text parts in general based on a priority system to fit a page limit?

Pseudocode

This is a core sentence that should always be included.
\optional{1}{This is a high priority explanation that should only be removed when absolutely necessary.} 
\optional{100}{This only reinforces a previous statement and can safely be removed.}

This is only a very basic example. Ideally there should be dependencies (only show x if y is shown as well) and local priority to fit a page.

Does anything like this exist?

1 Answers1

2

As far as I know something like this does not exist, but it is not too difficult to implement.

A possible implementation is to check at the end of the document if you are over the page limit. If this is the case, then you store the highest number found in the \optional macros in the .aux file. On the next run, you skip all optional content with this number or higher. If the remaining output is still over the page limit, then you store the highest number of the content that is still being displayed during the run in the .aux file. Then in the next run the threshold for removal will be the second highest number, and so on.

In the MWE below this is implemented in three parts. Within \AtBeginDocument, which is executed after the .aux file is read, the code checks if a macro \chkpriority was defined. If not then this is the first run and the macro is set to -1.

The second part is the macro \optional. If \chkpriority is -1 then the content is shown because it is still unknown if it should be removed or not, but the priority value is stored if it is the highest so far. If there was a number defined from a previous run in \chkpriority, and the value of the current content is equal or higher than the stored value, then the content is not displayed. If the value is lower than the stored value the content is displayed, and potentially recorded as the highest value of displayed content in the current run.

The third part is within \AtEndDocument. Here the highest value for shown content is written to the .aux file. If no optional content is shown (because all optional content was all removed or because there were no \optional statements at all) then the default value of 0 is written.

Code:

\documentclass{article}
\usepackage{lipsum}
\usepackage{kantlipsum}
\def\maxpages{3}
\def\highestpriority{0}

\AtBeginDocument{% \ifdefined\chkpriority\else% \gdef\chkpriority{-1}\fi% }

\def\optional#1#2{% \message{Checking content with priority #1.^^J}% \ifnum\chkpriority=-1% \message{No stored priority found, show content.^^J}% #2\ifnum#1>\highestpriority% \xdef\highestpriority{#1}\fi% \else% \ifnum#1=\chkpriority\relax\message{Equal to stored, remove content.^^J}\else% \ifnum#1>\chkpriority\relax\message{Higher than stored, remove content.^^J}\else% \message{Lower than stored, show content.^^J} #2\ifnum#1>\highestpriority% \xdef\highestpriority{#1}\fi% \fi\fi\fi% } \makeatletter% \AtEndDocument{\message{Currently \thepage\space pages.^^J}% \ifnum\value{page}>\maxpages% \message{This is more than the page limit of \maxpages.^^J}% \message{Highest priority found within displayed content: \highestpriority.^^J}% \message{Run again to remove content with priority \highestpriority\space or more.^^J}% \else% \message{This is below the page limit of \maxpages.}% \fi% \immediate\write@auxout{\gdef\string\chkpriority{\highestpriority}}% } \makeatother% \begin{document} This is a core sentence that should always be included. \optional{5}{\lipsum[1-20]} \optional{10}{\kant[1-10]} \end{document}

This leads to the following output in the terminal and log file during consecutive runs (cleaned up to show only the output from the \message commands):

First run:

Checking content with priority 5.
No stored priority found, show content.
Checking content with priority 10.
No stored priority found, show content.
Currently 7 pages.
This is more than the page limit of 3.
Highest priority found within displayed content: 10.
Run again to remove content with priority 10 or more.

During the first run all content is included in the output pdf.

Second run:

Checking content with priority 5.
Lower than stored, show content.
Checking content with priority 10.
Equal to stored, remove content.
Currently 4 pages.
This is more than the page limit of 3.
Highest priority found within displayed content: 5.
Run again to remove content with priority 5 or more.

During the second run the command \lipsum[1-20] is included in the pdf but the command \kant[1-10] is not included.

Third run:

Checking content with priority 5.
Equal to stored, remove content.
Checking content with priority 10.
Higher than stored, remove content.
Currently 1 pages.
This is below the page limit of 3.

During the third run (and any further runs) only the core sentence is displayed.

Note that you may need to delete the .aux file and run again a few times if you add optional content later, because otherwise it may be removed while it still fits.

Dependencies can be implemented by giving dependent content a higher or equal number as the content it depends on. I'm not sure what you mean with local priority to fit a page.

Finally note that this is a proof of concept implementation that is not very thouroughly tested and likely has several limitations (for example regarding the kinds of content that can go into the second argument of \optional).

Marijn
  • 37,699