1

I see from the documentation that seqsplit is supposed to work in mathmode.

However, I have the following:

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

And get this error:

! 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]

It's not clear to me which part of this is underspecified in { or }. Is it fighting with the e^{}, thinking these are closing seqsplit?

What's strange is the output is correct, but I still have to answer the prompts.

4
  • \seqsplit can break sequences of characters; just place e^{...} outside it. – egreg Nov 6 '18 at 7:45
  • you would get essentially the same error if you did {1} {2} {^} {2567} which is more or less what you are asking seqsplit to turn your input into. – David Carlisle Nov 6 '18 at 7:58
  • 2
    irrelevant but notice that $4.12..e2567$ or $4.12..E2567$ or $4.12...\cdot 10^{2567}$, or etc... are all better than $4.12... e^{2567}$ which is mathematically unsound notation as it raises confusion about whether $e$ is Euler's constant. – user4686 Nov 6 '18 at 9:51
  • Thanks, jfbu, I actually noticed that too after posting and that was my true solution, switching to capital E and no power, but left the question up to understand the mechanics. – Mittenchops Nov 6 '18 at 15:39
2

I propose a different macro:

\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}

Each digit is turned into a macro that typesets the digit followed by a glob of zero glue, but stretchable up to 2mu, and by a penalty that allows a line break. The period, however, removes the penalty, so there is no allowed break before and after it. There is no problem with the exponent, because penalties there do nothing.

enter image description here

1

It would be a pity to hardcode your 1000! in the LaTeX source.

\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}

enter image description here

I deliberately do not use e^{..} notation, see my comment

1
  • if required we can also obfuscate the middle digits into dots (but we needed some computation first to get the number of them; we can always get both exponent and leading digits via \xintFloatFac with suitable \xintDigits float precision, but to get the trailing digits is more difficult without some exact computation of the whole thing). – user4686 Nov 6 '18 at 10:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.