5

How to create the following symbol? enter image description here

  • 6
    Just out of curiosity: what does this notation mean? Is it equivalent to a regular fraction? So (x-x0)/rho(x0,x1)? – Karlo Aug 14 '16 at 19:00
  • 2
    $\varPhi^{n,n}(x) = f_0 + \underline{x-x_0}\mkern-2mu\big/\mkern-2mu\overline{\rho(x_0,x_1)}$ – Henri Menke Aug 14 '16 at 19:19
  • 2
    @HenriMenke, please turn your comment into an answer. – heather Aug 14 '16 at 21:15
  • The formatting directives \mkern-2mu and \big/ appear to be OK for a font size of 10pt and Computer Modern math fonts, but they aren't quite as good for other font sizes and other math font families. A TikZ-based approach to draw the zig-zag line may be called for. – Mico Aug 14 '16 at 21:31
7

The easiest way is to just use two rules and connect them with a slash kerned by a little negative space. This does not scale with the content where a more sophisticated approach is needed, i.e. putting things in a box and measure the height.

\documentclass{article}
\usepackage{amsmath}
\newcommand\fractional[2]{%
  \underline{#1}\mkern-2mu\raise .1ex \hbox{$\big/$}\mkern-1.5mu\overline{#2}
}
\begin{document}
\[ \varPhi^{n,n}(x) = f_0 + \fractional{x-x_0}{\rho(x_0,x_1)} \]
\end{document}

enter image description here


Here is a variant that scales almost nicely.

\documentclass{article}
\usepackage{amsmath}
\newcommand\fractional[2]{%
  \mathpalette\dofractional{{#1}{#2}}
}
\newcommand\dofractional[2]{%
  \dofractionalindeed#1#2
}
\newcommand\dofractionalindeed[3]{%
  \setbox0=\hbox{$#1#2$}%
  \setbox1=\hbox{$#1#3$}%
  \ifdim\ht0>\ht1
    \dimen0=\dimexpr\ht0+1pt
  \else
    \dimen0=\dimexpr\ht1+1pt
  \fi
  \ifdim\dp0>\dp1
    \dimen1=\dimexpr\dp0+1pt
  \else
    \dimen1=\dimexpr\dp1+1pt
  \fi
  \rlap{\vrule height -\dimen1 width \wd0 depth \dimexpr\dimen1+\fontdimen8\textfont3}
  \box0
  \mkern-2mu
  \mathord{\left/\vrule height \dimen0 depth \dimen1 width 0pt\right.\kern-\nulldelimiterspace}
  \mkern-2mu
  \rlap{\vrule height \dimexpr\dimen0+\fontdimen8\textfont3 width \wd1 depth -\dimen0}
  \box1
}
\begin{document}
\[ \varPhi^{n,n}(x) = f_0 + \scriptscriptstyle \fractional{x-x_0}{\rho(x_0,x_1)} \]
\[ \varPhi^{n,n}(x) = f_0 + \scriptstyle \fractional{x-x_0}{\rho(x_0,x_1)} \]
\[ \varPhi^{n,n}(x) = f_0 + \fractional{x-x_0}{\rho(x_0,x_1)} \]
\[ \varPhi^{n,n}(x) = f_0 + \textstyle \fractional{\int x-x_0}{\sum \rho(x_0,x_1)} \]
\[ \varPhi^{n,n}(x) = f_0 + \fractional{\int x-x_0}{\sum \rho(x_0,x_1)} \]
\end{document}

enter image description here

  • Nice answer! But allow me a few minor remarks: 1) You shouldn’t use \box1 and \dimen1 for local assignments. 2) I don’t understand the reason for the initial \dimen0=\dimexpr\ht0+\dp0 \dimen1=\dimexpr\ht1+\dp1. 3) IMHO, a \dimexpr is best closed with \relax before an \else (at least), it’s too easy to overlook what comes after the conditional. 4) (Not sure about this one, needs experiments.) You might also want to consider locally resetting \delimiterfactor and \delimitershortfall (see, e.g., the output of your fourth example; true that the available sizes are those…). – GuM Sep 17 '16 at 23:17
  • @GustavoMezzetti (1) Why shouldn't I use \box1 and \dimen1? From the TeXbook I know »Furthermore, plain TeX reserves \dimen0 to \dimen9, \skip0 to \skip9, \muskip0 to \muskip9, and \box0 to \box9 for “scratchwork”; these registers are never allocated by the \new... operations. We have seen that \count0 through \count9 are special, and \box255 also turns out to be special; so those registers should be avoided unless you know what you are doing.« – Henri Menke Sep 18 '16 at 19:47
  • @GustavoMezzetti (2) These were just leftovers from a previous attempt I forgot to delete. – Henri Menke Sep 18 '16 at 19:47
  • @GustavoMezzetti (3) If you look carefully you will notice that every assignment and comparison of a register is followed by a space (newline counts as space). When TeX is scanning for number it will stop as soon as a non-number character is encountered. If you look in plain.tex you will find that all assignments are followed by a space rather than \relax. – Henri Menke Sep 18 '16 at 19:47
  • 1
    @HenriMenke If you do \ifdim\ht0>\ht1 \dimen0=\dimexpr\ht0+1pt \else… and the test returns true, then TeX will expand the \else before doing the assignment, because the \dimexpr has not yet ended. This will remove everything up to \fi, which will again be expanded; if something follows that can be interpreted as a number, you'd be in trouble. Add \relax as Gustavo suggested. About not using odd numbered registers for local assignments, look for “save stack buildup” in the index of the TeXbook and go to pages 301 and 346. – egreg Sep 18 '16 at 20:44
5

The following solution draws the complete line with all three parts in one drawing operation. The advantages are

  • proper line join,
  • constant line width.

The drawing is done with TikZ (which would also allow to change the line styles, line joins, and line caps).

  • The correct line width is extracted from the font dimen register:

    \fontdimen8\<text|script|scriptscript>font3
    
  • The formula is separated from the line by a gap of three line widths in \underline and \overline. Also, TeXs sets an outer margin below/above the line with the amount of one line width.

  • \overline uses a cramped math style for the formula. For example, superscripts are lowered a bit. LuaTeX has commands for setting the cramped math styles. Without LuaTeX, the solution uses macro \cramped of package mathtools.

Implementation with example and test cases:

\documentclass{article}

\usepackage{ifluatex}
\ifluatex
  \IfFileExists{luatex85.sty}{\usepackage{luatex85}}{}
  % LuaTeX provides \<mathstyle>cramped
\fi
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname crampedscriptstyle\endcsname\relax
  \usepackage{mathtools} % for \cramped
  \newcommand*{\SetCrampedStyle}[2]{%
    \cramped[#1]{#2}%
  }
\else
  \newcommand*{\SetCrampedStyle}[2]{%
    {%
      \ifx#1\displaystyle\crampeddisplaystyle
      \else\ifx#1\textstyle\crampedtextstyle
      \else\ifx#1\scriptstyle\crampedscriptstyle
      \else\crampedscriptscriptstyle
      \fi\fi\fi
      #2%
    }%
  }
\fi
\usepackage{tikz}

\makeatletter
\newcommand*{\fractional}[2]{%
  \mathpalette{\@fractional{#1}{#2}}{}%
}
\newcommand*{\fractionalAngle}{65}
\newcommand*{\@fractional}[4]{%
  % #1, #2: arguments of \fractional
  % #3: math style
  % #4: unused
  %
  % Get the line width for this math style
  \edef\@LineWidth{%
    \the\fontdimen8
    \ifx#3\displaystyle\textfont
    \else\ifx#3\textstyle\textfont
    \else\ifx#3\scriptstyle\scriptfont
    \else\scriptscriptfont
    \fi\fi\fi
    3%
  }
  %
  % Set the left and right part in boxes for measurment and usage.
  % Note the cramped style for the right part as in \overline and \sqrt.
  \sbox0{$#3#1\m@th$}%
  \sbox2{$#3\SetCrampedStyle{#3}{#2}\m@th$}%
  %
  % Calculate the total height for the slanted line
  \edef\@SlashTotalHeight{%
    \the\dimexpr
      \dp0 + \ht2
      + \@LineWidth * 7 % 2 * (3 [space] + 1/2 [line])
    \relax
  }%
  %
  % Calculate the width of the slanted line
  \pgfmathsetlengthmacro\@SlashWidth{%
    \@SlashTotalHeight * cos(\fractionalAngle)%
  }%
  %
  \begin{tikzpicture}[
    inner sep=0pt,
    outer sep=0pt,
    baseline=(Left.base),
    line width=\@LineWidth,
  ]
    \draw[overlay] % Bounding box is set later
      % Left and right part are set as nodes
      node[anchor=base east] (Left) {\copy0}
      ++(\@SlashWidth, 0)
      node[anchor=base west] (Right) {\copy2}
      %
      % Line is drawn
      (Left.south west)
      ++(0, -3.5\pgflinewidth)
      -- ++(\wd0, 0)
      -- ++(\@SlashWidth, \@SlashTotalHeight)
      -- ++(\wd2, 0)
    ;%
    % Bounding box
    \useasboundingbox[outer sep=-.5\pgflinewidth]
      (Left.south west) ++(0, -5\pgflinewidth)
      (Right.north east) ++(0, 5\pgflinewidth)
    ;%
  \end{tikzpicture}%
}
\makeatother


% Testing
\usepackage{amsmath}
\usepackage{color}
\newcommand*{\Annot}[1]{\text{\scriptsize\quad(#1)}}

\begin{document}
\[ \varPhi^{n,n}(x) = f_0 + \fractional{x-x_0}{\rho(x_0,x_1)} \]
\[
  \underline{x_0}
  \begingroup\color{red}
    \fractional{\color{black}x_0}{\color{black}x^{\color{red}0}}
  \endgroup
  \overline{x^{\color{red}0}}
  \Annot{Positions}
\]
\[
  \def\test{
    {\color{blue}\fractional{\color{black}x_0}{\color{black}x^0}}
  }
  \test\,
  \scriptstyle\test\,
  \scriptscriptstyle\test
  \Annot{Line widths}
\]
\[
  \setlength{\fboxsep}{0pt}
  \setlength{\fboxrule}{.2pt}
  \def\test#1{\textcolor{red}{\fbox{\color{black}$#1$}}}%
  \test{\underline{x_0}}\,
  \test{\fractional{x_0}{x^0}}\,
  \test{\overline{x^0}}
  \Annot{Bounding boxes}
\]
\end{document}

Result

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.