![如何使用 LaTeX 排版十倍幂(幂之塔)?](https://linux22.com/image/278850/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8%20LaTeX%20%E6%8E%92%E7%89%88%E5%8D%81%E5%80%8D%E5%B9%82%EF%BC%88%E5%B9%82%E4%B9%8B%E5%A1%94%EF%BC%89%EF%BC%9F.png)
我该如何写x^x^x^x^x^x^x^x^x^x
?
我的 LaTeX 发行版不想吃它,它在双倍功率 x^x^x 时停止吞食东西。我的目标是从本质上用堆叠在一起的 X 构建一个望远镜。别问,这是我的幽默感。
答案1
\documentclass{article}
\def\powertower#1#2{#1\ifnum#2>1 ^{\powertower{#1}{\numexpr#2-1\relax}}\fi}
\begin{document}
$\powertower{x}{100}$
\end{document}
答案2
\documentclass[12pt]{article}
\begin{document}
\[ x^{x^{x^{x^{x^{x^{x^{x^{x^x}}}}}}}} \]
\end{document}
答案3
我将这段代码献给 Sean。:)
长命expl3
!:)
\documentclass{article}
\usepackage{expl3}
\usepackage{xparse}
\ExplSyntaxOn
\cs_new:Npn \paulo_epicrecursion:nn #1 #2 {
#1^{ \int_compare:nTF { #2 > 1 } {
\paulo_epicrecursion:nn { #1 } { \int_eval:n { #2 - 1 } }
} {
#1
} }
}
\NewDocumentCommand{ \powertower } { m m } {
\paulo_epicrecursion:nn { #1 } { #2 }
}
\ExplSyntaxOff
\begin{document}
$\powertower{x}{10}$
\end{document}
输出:
更新:egreg 精辟地指出,上述代码生成了一长串嵌套\int_eval:n
调用。优化如下:
\documentclass{article}
\usepackage{xparse}
\ExplSyntaxOn
\cs_new:Npn \paulo_epicrecursion:nn #1 #2
{
#1^{
\int_compare:nTF { #2 > 1 }
{ \paulo_epicrecursion:nx { #1 } { \int_eval:n { #2 - 1 } } }
{ #1 }
}
}
\NewDocumentCommand{ \powertower } { m m }
{
\paulo_epicrecursion:nn { #1 } { #2 }
}
\cs_generate_variant:Nn \paulo_epicrecursion:nn { nx }
\ExplSyntaxOff
\begin{document}
$\powertower{x}{10}$
\end{document}
这里的技巧是生成的变体。正如 egreg 所解释的,第一个调用不需要完全展开,但递归调用需要。
答案4
怎么?害怕超越255
?我才不怕呢!
这是获得的$\epictower{x}{600}$
。
这复现了确切地本来会做什么
TeX
(如果不是因为 255 个组级别的限制)包括TeX
在右侧考虑额外水平空间的一个相当奇怪的特征。2015 年更新。我忘了在 2013 年说过我指的是什么:水平空白延伸到电力塔的右侧,在字符字形的侧面。带有 600 x 的图像没有显示由此产生的(大)额外水平空间,因为图形被剪裁到包含的墨水中。下面带有较短楼梯的图像使用 fbox 显示额外的空白,查看最右侧字符的右侧到 fbox 框架的距离。您还可以在 fbox 内尝试 David Carlisle 的宏(使用
\fboxsep=0pt
或更确切地说-0.4pt
)。
在下图中,左上角是生成的\epictower
,右下角是原始内容,以证明水平和垂直放置是正确的(字体大小设置60pt
为标准大小)。
代码如下:
\documentclass{article}
% use this for 600 x's!
% \usepackage [paperheight=65cm,paperwidth=100cm]{geometry}
\usepackage {geometry}
\pagestyle{empty}
\makeatletter
\newdimen \epic@x
\newdimen \epic@y
\newdimen \epic@extrax
\newdimen \epic@extray
\newbox \epic@one
\newbox \epic@two
\newcommand{\epictower}[2]{\ifcase #2\relax
1\or #1\or {#1}^{#1}\or {#1}^{{#1}^{#1}}\else \epic@tower {#1}{#2}\fi }
\def\epic@tower #1#2{%
\sbox\epic@one{\m@th $\scriptscriptstyle #1$}%
\sbox\epic@two{\m@th $\scriptscriptstyle {#1}^{#1}$}%
\epic@x=\wd\epic@one
\epic@extrax=\wd\epic@two
\advance\epic@extrax by -\epic@x
\advance\epic@extrax by -\epic@x
\epic@y=\ht\epic@two
\advance\epic@y by -\ht\epic@one
\epic@extray=\ht\epic@one
\advance\epic@extray by -\epic@y
\toks@ \expandafter{\the\numexpr #2-3}%
{#1}^{{#1}^{%
\setlength{\unitlength}{1sp}%
\begin{picture}({\numexpr (#2-2)*\epic@x+(#2-3)*\epic@extrax\relax},%
{\numexpr (#2-2)*\epic@y+\epic@extray\relax})
\count@\z@
\loop
\put (\numexpr \count@ * \epic@x\relax,%
\numexpr \count@ * \epic@y\relax){\copy\epic@one}%
\ifnum\the\toks@>\count@
\advance\count@ \@ne
\repeat
\end{picture}}}}
\makeatother
\begin{document}\thispagestyle{empty}
\fboxsep-.4pt
\fontsize{60}{60}
\newcommand{\testtexpowers}[1]{%
\setbox 1 \hbox{$\scriptscriptstyle #1$}%
\setbox 2 \hbox{$\scriptscriptstyle #1^{\fbox{\copy1}}$}%
\setbox 3 \hbox{$\scriptscriptstyle #1^{#1^{\fbox{\copy1}}}$}%
\setbox 4 \hbox{$\scriptscriptstyle #1^{#1^{#1^{\fbox{\copy1}}}}$}%
\setbox 5 \hbox{$\scriptscriptstyle #1^{#1^{#1^{#1^{\fbox{\copy1}}}}}$}%
\setbox 6 \hbox{$\scriptscriptstyle #1^{#1^{#1^{#1^{#1^{\fbox{\copy1}}}}}}$}%
\setbox 7 \hbox{$\scriptscriptstyle #1^{#1^{#1^{#1^{#1^{#1^{\fbox{\copy1}}}}}}}$}%
\setbox 8 \hbox{$\scriptscriptstyle #1^{#1^{#1^{#1^{#1^{#1^{#1^{\fbox{\copy1}}}}}}}}$}%
\setbox 9 \hbox{$\scriptscriptstyle #1^{#1^{#1^{#1^{#1^{#1^{#1^{#1^{\fbox{\copy1}}}}}}}}}$}%
\leavevmode\rlap{\rlap{\rlap{\rlap{\rlap{\rlap{\rlap{\rlap{\fbox{\box1}}\fbox{\box2}}\fbox{\box3}}\fbox{\box4}}\fbox{\box5}}\fbox{\box6}}\fbox{\box7}}\fbox{\box8}}\fbox{\box9}}
\testtexpowers{x}
\testtexpowers{X}
\testtexpowers{xX}
\clearpage
\fbox{$\epictower {x}{1}$}\fbox{$x$}\hrule\fbox{$x$}
\hrule
\fbox{$\epictower {x}{2}$}\fbox{$x^x$}\hrule\fbox{$x^x$}
\hrule
\fbox{$\epictower {x}{3}$}\fbox{$x^{x^x}$}\hrule\fbox{$x^{x^x}$}
\hrule
\fbox{$\epictower {x}{4}$}\fbox{$x^{x^{x^x}}$}\hrule\fbox{$x^{x^{x^x}}$}
\hrule
\fbox{$\epictower {x}{5}$}\fbox{$x^{x^{x^{x^x}}}$}\hrule\fbox{$x^{x^{x^{x^x}}}$}
\hrule
\fbox{$\epictower {x}{6}$}\fbox{$x^{x^{x^{x^{x^x}}}}$}\hrule\fbox{$x^{x^{x^{x^{x^x}}}}$}
\hrule
\clearpage
\fbox{$\epictower {X}{1}$}\fbox{$X$}\hrule\fbox{$X$}
\hrule
\fbox{$\epictower {X}{2}$}\fbox{$X^X$}\hrule\fbox{$X^X$}
\hrule
\fbox{$\epictower {X}{3}$}\fbox{$X^{X^X}$}\hrule\fbox{$X^{X^X}$}
\hrule
\fbox{$\epictower {X}{4}$}\fbox{$X^{X^{X^X}}$}\hrule\fbox{$X^{X^{X^X}}$}
\hrule
\fbox{$\epictower {X}{5}$}\fbox{$X^{X^{X^{X^X}}}$}\hrule\fbox{$X^{X^{X^{X^X}}}$}
\hrule
\fbox{$\epictower {X}{6}$}\fbox{$X^{X^{X^{X^{X^X}}}}$}\hrule\fbox{$X^{X^{X^{X^{X^X}}}}$}
\hrule
\end{document}
% comment-out the preceding, sets page dimensions in geometry
% only limited by TeX's \maxdimen !
$\epictower{x}{600}$
\end{document}