在换行符处插入 LaTeX 代码

在换行符处插入 LaTeX 代码

有没有办法在行间插入任意 (La)TeX 代码排版线?

我知道这在 (La)TeX 中实际上是不可能的。但是看到所有有趣的chickenize功能都以行为基础应用,我开始怀疑 LuaTeX 是否可以提供一种简单的机制来实现这一点。举例来说:我希望在“nulla”之后立即排版带有时间的框:

\documentclass{article}

\usepackage{datetime}

\newcommand{\doatlinebreak}[1]{#1}


\begin{document}

Vivamus pharetra posuere sapien. Nam consectetuer. 
Sed aliquam, nunc eget euismod ullamcorper, lectus nunc 
ullamcorper orci, fermentum bibendum enim nibh eget ipsum. 
Donec porttitor ligula eu 
dolor. \doatlinebreak{\makebox[0pt][l]{\currenttime}}Maecenas 
vitae nulla consequat libero cursus venenatis.

\end{document}

答案1

A这可能会让你开始在每一行的末尾插入一个字形节点

在此处输入图片描述

\documentclass{article}

\directlua{
%
function my_post_lb_filter(h,c)
local cntr=0

for n in node.traverse(h) do
% pull out the boxes and add A
if n.id==0 then
local  newn= node.new(node.id("glyph"))
newn.font=font.current()
newn.char=65 % this is a single character box, for A
node.insert_after(n.list,node.tail(n.list),newn)
end
%
end
return h
end
luatexbase.add_to_callback('post_linebreak_filter', my_post_lb_filter, 'add A at eol')
}



\begin{document}

Vivamus pharetra posuere sapien. Nam consectetuer. 
Sed aliquam, nunc eget euismod ullamcorper, lectus nunc 
ullamcorper orci, fermentum bibendum enim nibh eget ipsum. 
Donec porttitor ligula eu 
dolor. Maecenas 
vitae nulla consequat libero cursus venenatis.

\end{document}

答案2

不需要 LuaTeX。只需使用\marginpar

\documentclass{article}

\usepackage{datetime}

\begin{document}

Vivamus pharetra posuere sapien. Nam consectetuer. 
Sed aliquam, nunc eget euismod ullamcorper, lectus nunc 
ullamcorper orci, fermentum bibendum enim nibh eget ipsum. 
Donec porttitor ligula eu 
dolor. \marginpar{\currenttime}Maecenas 
vitae nulla consequat libero cursus venenatis.

\end{document}

或者,使用 TeXbook 问题 14.28 的答案:

\documentclass{article}

\usepackage{datetime}

\newcommand{\doatlinebreak}[1]{%
  \strut\vadjust{
    \kern-\dp\strutbox
    \vtop to \dp\strutbox{
      \baselineskip=\dp\strutbox
      \vss\hbox to \textwidth{\hss\rlap{\quad#1}}\null
    }
  }%
}


\begin{document}

Vivamus pharetra posuere sapien. Nam consectetuer. 
Sed aliquam, nunc eget euismod ullamcorper, lectus nunc 
ullamcorper orci, fermentum bibendum enim nibh eget ipsum. 
Donec porttitor ligula eu 
dolor. \doatlinebreak{\currenttime}Maecenas 
vitae nulla consequat libero cursus venenatis.

\end{document}

在此处输入图片描述

相关内容