通过 Lua,我可以直接在 PDF 中编写和使用对象:
local num = pdf.immediateobj("stream", "\\(a^2+b^2=c^2\\)", "/Type /SomeType /Subtype /SomeSubtype")
我如何通过expl3
简单的 LaTeX 命令执行相同操作以使其在 pdfLaTeX 和 LuaLaTeX 中工作?
答案1
您可以使用 l3pdf 命令。我这样做了不是检查流内容的语法是否正确:
\documentclass{article}
\usepackage{l3pdf}
\ExplSyntaxOn
\pdf_uncompress:
\ExplSyntaxOff
\begin{document}
\ExplSyntaxOn
\pdf_object_new:nn {mystream}{stream}
\pdf_object_write:nn {mystream}
{{/Type /SomeType /Subtype /SomeSubtype}
{\(a^2+b^2=c^2\)}}
\pdf_object_ref:n {mystream}
some text ...
%to get only the number as requested in the comments
% make only sense for pdflatex and lualatex
\tl_set:Nx\l_tmpa_tl { \pdf_object_ref:n {mystream} }
\seq_set_split:NnV \l_tmpa_seq {~} { \l_tmpa_tl }
\seq_item:Nn\l_tmpa_seq{1}
\ExplSyntaxOff
\end{document}