Seqsplit 在数学模式下失败

Seqsplit 在数学模式下失败

我从文档中看到 seqsplit 应该在数学模式下工作。

但是,我有以下几点:

Since we know $1000! = \seqsplit{4.0238726007709377354370243392300398571937486421...105933983835777939410970027753472e^{2567}}$, we can represen...

并收到此错误:

! Missing { inserted.
<to be read again> 
                   \futurelet 
l.487 ...15933983835777939410970027753472e^{2567}}
                                                  $, we can represen...
? [ENTER]
! Missing } inserted.
<inserted text> 
                }
l.487 ...15933983835777939410970027753472e^{2567}}
                                                  , we can represent...
? [ENTER]

我不清楚 { 或 } 中哪一部分未指定。它是否与 e^{} 发生冲突,认为这些正在关闭 seqsplit?

奇怪的是输出是正确的,但我仍然需要回答提示。

答案1

我建议一个不同的宏:

\documentclass{article}
\usepackage{amsmath}
\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\longnumber}{m}
 {
  \group_begin:
  \int_step_inline:nnn { `0 } { `9 }
   {
    \char_set_active_eq:nc { ##1 } { __mittenchops_activenumber_##1: }
    \mathcode##1="8000\scan_stop:
   }
  \char_set_active_eq:nN { `. } \__mittenchops_activeperiod:
  \mathcode`.="8000\scan_stop:
  #1
  \group_end:
 }
\int_step_inline:nnn { `0 } { `9 }
 {
  \cs_new:cpn { __mittenchops_activenumber_#1: }
   {
    \mathchar#1\scan_stop:
    \mspace{0mu plus 2mu}
    \penalty0\scan_stop:
   }
 }
\cs_new:Npn \__mittenchops_activeperiod:
 {
  \unpenalty
  \mathchar`.\scan_stop:
  \mspace{0mu plus 2mu}
 }
\ExplSyntaxOff

\begin{document}

Since we know $1000! = \longnumber{4.023872600770937735437024339230
0398571937486421\dots105933983835777939410970027753472e^{2567}}$, 
we can represent...

\end{document}

每个数字都变成了一个宏,该宏排版数字后跟一团零粘连,但可拉伸至 2mu,并带有允许换行的惩罚。但是,句号会消除惩罚,因此不允许在句号前后换行。指数没有问题,因为那里的惩罚不起作用。

在此处输入图片描述

答案2

1000!在 LaTeX 源代码中进行硬编码会很可惜。

\documentclass{article}
\usepackage{amsmath}% provides \mspace

\usepackage{xintfrac}% provides \xintFac, \xintREZ

\makeatletter
\newcommand\IntToSplitableFloat[1]{%
% We assume input will expand to some (long, *positive*) integer
   % first we handle trailing zeros
   % (unfortunately xint does not provide auxiliaries to get the A, B, C
   %  from the \xintREZ output A/B[C])
   \expandafter\ITSF@parseinput
               \romannumeral0\xintrez{#1}%
   % attention that \xintLen expands its argument but treats it as a
   % number to normalize, so it removes leading zeros, and they may
   % occur as we have trimmed the leading digit. So we use \xintLength
   % but some \expandafter are needed.
   \edef\ITSF@nbofnextdigits
       {\expandafter\xintLength\expandafter{\ITSF@nextdigits}}%
   % compute the final exponent
   \edef\ITSF@exponent{\the\numexpr\ITSF@nbofnextdigits+\ITSF@exp}%
   \ITSF@lead.\mspace{0mu plus 2mu}%
   \expandafter\ITSF@loop\ITSF@nextdigits\relax
   \unpenalty\unskip\nobreak\;10^{\ITSF@exponent}%
}

\def\ITSF@parseinput #1#2/#3[#4]{%
% make global definitions to keep possibility to reuse the
% parsed integer afterwards without recomputing it
  \gdef\ITSF@lead{#1}\gdef\ITSF@nextdigits{#2}\gdef\ITSF@exp{#4}%
  % we assume here #3 is 1 with no error checking...
}

\def\ITSF@loop #1{%
  \if#1\relax\else#1\mspace{0mu plus 2mu}\penalty0 \expandafter\ITSF@loop\fi
}
\makeatother

\begin{document}
Since we know that $1000! = \IntToSplitableFloat{\xintFac{1000}}$, we
feel that much happier.
\end{document}

在此处输入图片描述

我故意不使用e^{..}符号,请参阅我的评论

相关内容