1

I would like to append suitable ordinal suffixes for inline fractions similar to capabilities provided by the engord package from the oberdiek bundle.

Let me clarify. I want to use a macro \engordfrac{2}{3} for inline text fractions to automatically obtain 2/3rd in the output. Similarly, \engordfrac{4}{5} should produce 4/5th in the output.

I am including a MWE to illustrate example of the engord package, and the desired output in 2nd paragraph below.

\documentclass{article}
\usepackage{nicefrac}
\usepackage{engord}
\begin{document}
This is the \engordnumber{1} ever time the runner finished
\engordnumber{2} in the race. This was her \engordnumber{14}
ever race.   % just an example demonstration of engord package capabilities

\bigskip

Oh no! I paid \nicefrac{2}{3}rd of the price you paid for 
only \nicefrac{1}{4}th of the quantity.  % need to replace nicefrac with a suitable macro
\end{document}

engordnum_example example frac

How can I achieve this? If plain old TeX is difficult, luatex works for me if it helps. It does not necessarily have to be based on xfrac or nicefrac as long the desired result is achieved. I only suggested it in the title because these look typographically better.

PS: I am unsure of what is the correct (typographically accepted) way to typeset 2/3rd, 1/4th and other inline fractions.

1
  • 1
    For the 2/3rd terms, shouldn't it really be 2/3rds, to correspond to the way one would say it out loud: "I paid two thirds of the price...".
    – Mico
    Jul 13, 2018 at 15:58

2 Answers 2

2

(updated the answer to make fuller use of LuaLaTeX)

Since you're ok with using LuaLaTeX, I think it's natural to set up a Lua function that replicates some of the work of the engord package. Specifically, in the code shown below the Lua function myord determines whether the suffix string for a given integer should be st, nd, rd, or th. The suffix string can be affixed to the output of \nicefrac in two different ways, depending on whether the suffix string should be full-sized (as is shown in your screenshot) or have the same size as the denominator term of \nicefrac. The code below provides two LaTeX macros to perform this task. Choose whichever form better suits your formatting needs.

enter image description here

\documentclass{article}
\usepackage{nicefrac}

\makeatletter\let\percentchar\@percentchar\makeatother
\directlua{ % define a function that prints 2-letter ordinal strings
  function myord ( n )     % n: some positive number
    n = n \percentchar 100 % modulo-100
    if     m>3 and m<21           then tex.sprint ( "th" )
    elseif m \percentchar 10 == 1 then tex.sprint ( "st" ) 
    elseif m \percentchar 10 == 2 then tex.sprint ( "nd" )
    elseif m \percentchar 10 == 3 then tex.sprint ( "rd" )
    else                               tex.sprint ( "th" )
    end
  end 
}
\newcommand\myord[1]{\directlua{myord(#1)}} % LaTeX "wrapper macro"

\newcommand{\myfracA}[2]{\nicefrac{#1}{#2}\myord{#2}}
\newcommand{\myfracB}[2]{\nicefrac{#1}{#2\myord{#2}}}

\begin{document}
\myfracA{2}{3}, \myfracA{3}{4}

\myfracB{2}{3}, \myfracB{3}{4}
\end{document}
1
  • thank you for your answer. This does work. However, I think Bernard's answer may be slightly better as it will work for pdflatex also. It leverages strength of existing packages without redefining the logic to come up with appropriate suffixes. However, appreciate both your answers. They absolutely work. Jul 13, 2018 at 17:33
3

Is it something like this you're after?

\documentclass{article}
\usepackage{nicefrac}
\usepackage{engord}
\newcommand{\ordfrac}[2]{\nicefrac{#1}{\engordnumber{#2}}}

\begin{document}

This is the \engordnumber{1} ever time the runner finished
\engordnumber{2} in the race. This was her \engordnumber{14}
ever race. % just an example demonstration of engord package capabilities

\bigskip

Oh no! I paid \ordfrac{2}{3} of the price you paid for
only \ordfrac{1}{4} of the quantity. % need to replace nicefrac with a suitable macro

\end{document}

enter image description here

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .