0

I have a long equation which I am trying to fit into a single line:

\documentclass[a4paper,11pt,oneside]{article}

%%% DOCUMENT SETUP %%% \PassOptionsToPackage{medium}{titlesec}

% packages and configurations come here (see list below). \graphicspath{{images/}}

\title{My title} \author{Myself}

\date{\today{}}

\begin{document} \maketitle

\newcommand{\indicator}[1]{\mathbbm{1}_{{#1}}} \newcommand{\sgn}{\mathrm{sgn}}

\begin{align} \Lambda= \frac{1}{x}\left( \indicator{z\geq0} -e^{-xt}\Phi\left(\beta_0\right) +\frac{e^{-zy}}{2}\left( e^{-zp}\left(\frac{y}{p}-1\right)\Phi\left(\sgn(z)\beta_1\right) -e^{zp}\left(\frac{y}{p}+1\right)\Phi\left(-\sgn(z)\beta_2\right) \right) \right) \end{align} \end{document}

Based on this answer, I have tried to compact the equation by modifying the values of \thinmuskip and \medmuskip:

\begingroup
\setlength{\thinmuskip}{0mu}
\setlength{\medmuskip}{0mu}
\begin{align}
    \Lambda=
    \frac{1}{x}\left(
        \indicator{z\geq0}
        -e^{-xt}\Phi\left(\beta_0\right)
        +\frac{e^{-zy}}{2}\left(
            e^{-zp}\left(\frac{y}{p}-1\right)\Phi\left(\sgn(z)\beta_1\right)
            -e^{zp}\left(\frac{y}{p}+1\right)\Phi\left(-\sgn(z)\beta_2\right)
        \right)
    \right)
\end{align}
\endgroup

However I am getting the following errors:

! Incompatible glue units.               \setlength{\thinmuskip}{0mu}
! Illegal unit of measure (pt inserted). \setlength{\medmuskip}{0mu}

Moreover, the string u! appears in my output at the place where the group begins.

There are other questions on this site about this sort of error, such as this, but it seems unrelated to the problem at hand.

What is causing my code to fail here?

Edit: packages/settings for my document

\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage{bbm}
\usepackage{bm}

\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry} \usepackage{graphicx} \usepackage[colorlinks=true,allcolors=blue]{hyperref} \usepackage[authoryear]{natbib} \usepackage{titlesec} \usepackage[dvipsnames]{xcolor} \usepackage[normalem]{ulem} \usepackage{soul} \usepackage{color} \usepackage{booktabs} \usepackage[textsize=footnotesize,tickmarkheight=3pt]{todonotes} \usepackage{setspace}

% MATHS % \usepackage{amsmath} \usepackage{amsthm} \usepackage{amssymb} \usepackage{bigints} \usepackage{mathrsfs} \usepackage{xfrac} \usepackage{yfonts} \usepackage{mathtools} \usepackage{upgreek} \usepackage{nccmath} \usepackage{scalerel} \usepackage{accents} \usepackage{nicefrac} \usepackage{mathtools}

\usepackage{subcaption} \usepackage[labelfont=bf]{caption}

\usepackage{changepage} \usepackage{enumitem} \usepackage{eurosym} \usepackage{indentfirst} \usepackage{bibentry} \usepackage{pifont}

\setlength\parindent{0pt}

\bibliographystyle{myauthordate3} \setcitestyle{authoryear,round,semicolon,}

\titleformat{\paragraph}[hang] {\normalfont\normalsize\bfseries}{}{1em}{} \titlespacing{\paragraph}{0pt}{3.25ex plus 1ex minus .2ex}{1.5ex plus .2ex} \titleformat{\subparagraph} {\normalfont\normalsize\bfseries}{\thesubparagraph}{1em}{} \titlespacing{\subparagraph}{\parindent}{3.25ex plus 1ex minus .2ex}{.75ex plus .1ex}

\makeatletter \def\today{% \two@digits{\the\day}-% \ifcase\month\or% Jan\or Feb\or Mar\or Apr\or May\or Jun\or% Jul\or Aug\or Sep\or Oct\or Nov\or Dec\fi-% \number\year% } \makeatother

\newcommand{\indicator}[1]{\mathbbm{1}_{{#1}}} \newcommand{\sgn}{\mathrm{sgn}}

\makeatletter \newcommand{\vast}{\bBigg@{4}} \newcommand{\Vast}{\bBigg@{5}} \makeatother

  • You shouldn't set \thinmuskip and \medmuskip with \setlength if you load the calc package. Do you see why we always ask for minimal examples? – egreg Dec 26 '23 at 15:53
  • @egreg I am not loading calc, at least directly. I will add some of the (math-related) packages I load. – Daneel Olivaw Dec 26 '23 at 15:55
  • As I said, a minimal example showing the issue is needed. – egreg Dec 26 '23 at 15:55
  • The edit is *not* a minimal example. Anyway, my answer covers the business. Note that it should be \DeclareMathOperator{\sgn}{sgn} not with \newcommand. – egreg Dec 26 '23 at 16:05
  • 1
    I suggest splitting this into two lines, using multline instead of align and breaking just before the plus sign. You'll have to size the first parenthesis, using \biggl( and indicate the break as `\ \left. to match the final parenthesis. Yes, a more complete example would have been helpful. – barbara beeton Dec 26 '23 at 16:14
  • @barbarabeeton what is missing from the example? – Daneel Olivaw Dec 26 '23 at 16:17
  • The example was not complete when I started experimenting. It lacked at least a document class. It has been completed since. – barbara beeton Dec 26 '23 at 16:27
  • @barbarabeeton okay thank you. I wasn't aware of multline and the left/right alignment behavior. – Daneel Olivaw Dec 26 '23 at 16:31
  • Not related to the problem, but don't load packages unless you actually need them, and don't load the same package more than once. – Ian Thompson Dec 27 '23 at 15:05

2 Answers2

3

The scalerel package loads calc. Once the latter package is called, it's not possible to set muskips with \setlength.

Just do

\thinmuskip=0mu
\medmuskip=0mu

instead of \setlength.

egreg
  • 1,121,712
1

There's been a lot of thought put into the default spacing. Instead of changing that, I would split the equation into two:

\documentclass[a4paper,11pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage{amsmath}
\usepackage{bbm}
\newcommand{\indicator}[1]{\mathbbm{1}_{\{#1\}}}
\DeclareMathOperator{\sgn}{sgn}
\begin{document}
\begin{multline}
    \Lambda=
    \frac{1}{x}\biggl(
        \indicator{z\geq0}
        -e^{-xt}\Phi(\beta_0)\\
        +\frac{e^{-zy}}{2}\Bigl(
            e^{-zp}\Bigl(\frac{y}{p}-1\Bigr)\Phi(\sgn(z)\beta_1)
            -e^{zp}\Bigl(\frac{y}{p}+1\Bigr)\Phi(-\sgn(z)\beta_2)
        \Bigr)
    \biggr)
\end{multline}
\end{document}

This renders as: code output

I've also changed out the \left and \right, since they aren't quite optimal in this case (I can't find the appropriate Q&A at the moment).

A postscript on minimal examples: we only need amsmath and bbm in order to compile the example. We only need the document class options and geometry to determine the size of the avaiable text area. Everything else makes your example (1) more difficult to follow and (2) not compilable as a single block of code.

Teepeemm
  • 6,708
  • I think you accidentally mis-matched the sizes of your parentheses pairs. – mickep Dec 26 '23 at 17:52
  • Please take a closer look at the parentheses -- the first (on the first line) and the last (at the end) don't match in size, and they should. (That's the benefit of \left ... \right, but that, of course, doesn't work on split lines.) – barbara beeton Dec 26 '23 at 17:53
  • @mickep Oops. Thanks for that. – Teepeemm Dec 26 '23 at 18:42
  • @barbarabeeton Oops. Thanks for that. – Teepeemm Dec 26 '23 at 18:42
  • @Teepeemm I was displaying the rest of packages in case one of them loaded the calc package. – Daneel Olivaw Dec 26 '23 at 18:48
  • @DaneelOlivaw But it would have been possible to comment out the various packages that you load to see if you still have the error. That would have narrowed things down to scalerel, even if you don't know why scalerel caused the problem. You also never placed your code into one block that we can copy and paste: in order to get the error you reported, I would need the first 4 lines of your first code block, then your third code block, some more of your first code block, your second code block, and then the end of your first code block. – Teepeemm Dec 26 '23 at 20:09