Giter Club home page Giter Club logo

Comments (4)

Sophanatprime avatar Sophanatprime commented on August 12, 2024

LaTeX 在执行到 \ifodd 时,还不知道自己要不要换页,所以 \value{page} 还是没换页时候的值。
应该告诉 LaTeX 还需要多少空间,在 LaTeX 决定要不要换页之后,才能得到想要的 \value{page}

\documentclass[fontset=windows,linespread=1.5625]{ctexart}
\usepackage[a4paper,twoside,top=35mm,bottom=35mm,left=28mm,right=26mm,showframe]{geometry}
\usepackage{zhlipsum}
\usepackage{needspace}

\newsavebox\makenotesbox
\newcommand{\makenotestext}
  {\begin{tabular}[b]{l}
     \hline
    《史记·十二本纪·项羽本纪》 \\
     \hline
   \end{tabular}}
\newcommand{\makenotes}
  {
    \par 
    \sbox{\makenotesbox}{\parbox[b]{\textwidth}{\makenotestext}}
    \needspace{%
      \ifdim\dp\makenotesbox>\maxdepth
        \dimexpr\ht\makenotesbox+\dp\makenotesbox-\maxdepth\relax
      \else \ht\makenotesbox\fi}
    \ifodd\value{page}
      \ifdim\pagegoal=\maxdimen \hbox{}\thispagestyle{empty}\fi
      \clearpage
      \thispagestyle{empty}%
      \hbox{}
    \fi
%   \null
%   \vfill
    \vspace*{\fill}
    \noindent \usebox{\makenotesbox}\newpage
  }

\begin{document}
\zihao{3}\fangsong
\zhlipsum[1-5][name=xiangyu]
\makenotes
\end{document}

from forum.

muzimuzhi avatar muzimuzhi commented on August 12, 2024

使用 \value{page} 获得的不一定是当前页数,于是对它的奇偶判断也会出错。比如,用在一个跨页的段落里时,不论插入 \value{page} 的位置对应输出后换页前还是换页后的部分,\value{page} 获得的总是换页前的页数。

这里需要「仅在 shipout/输出一页 时展开」,对应的就是 \write(见 TeX by Topic, sec. 12.6.3 Expansion and \write),缺点是需要第二次编译。这就是 ifoddpage 包封装的 \ifoddpage

PS:texlive 2023 开始,\special 获得了一个新的关键词 shipout\special shipout<general text> 可以和 \write 一样,仅在 shipout 时展开 <general text>。详见 https://tug.org/texlive/doc/texlive-en/texlive-en.html#x1-920009.2https://tex.stackexchange.com/q/681452

from forum.

Sophanatprime avatar Sophanatprime commented on August 12, 2024

在OP这种问题下,如果仅仅使用 \label 这类技术,最坏情况需要编译 n+1 次,而不是固定的两次吧,而且估计编译次数超过2次的概率比平时大。和 needspace 配合使用的话,当然是更好的选择。(除非取消某些页的 shipout,不用写入辅助文件的方式应该也行吧。)

\special 里好像不能放盒子?

from forum.

djunhao avatar djunhao commented on August 12, 2024

谢谢 @Sophanatprime 前辈提供的解决方案。
谢谢 @muzimuzhi 老师提供的信息,我好好研究一下。主要是本人的水平很菜,有些很简单的问题可能也需要很长时间看文档、搜索示例才能弄明白。汗!

from forum.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.