a \frac{}{} with knobs

What definition code gives mathematics mode output that looks like this?

Often $$A$$ | $$B$$ inline, and $\frac{A}{B}$ in display mode, is the notation for A if and only if B''.

If A \cirf B inline, and \fric{A}{B} in display mode, is the notation for A if B'', what is the best way to construct these macros such that:

(a) the if is iff capped with orthogonal knobs in opposite directions at its ends,

(b) the if like iff scales with its arguments,

(c) the if compiles everywhere the iff compiles?

(EDIT: changed if to cirf.)

• Better think of a name other than \if... ;). – cfr Oct 21 '15 at 2:27
• Why? Wouldn't redefining standard TeX macros make the editor of the journal like me even more ;) It'd make their typsetting much harder a job, with all the random compile errors it'd introduce in the issue. Every journal team consists of people who enjoy a challenge... – Guido Jorg Oct 21 '15 at 3:14
• If you're not careful, barbara will disappear you ;). – cfr Oct 21 '15 at 3:15
• I think your edit may be a bit too aggressive - I find it hard to understand what is wanted from your updated description. – Dai Bowen Oct 29 '16 at 12:32
• Is this better? (My edit before was what I ended up printing.) I am now starting to use this notation in papers and welcome anybody else who wants to use it. – Guido Jorg Oct 30 '16 at 7:00

Edit: a solution for fractions; see below.

Here's a solution for the first one (side-by-side, not the fraction), using rules.

\documentclass{article}
\usepackage{amsmath}
\newcommand{\hookheight}{8pt}
\newcommand{\hookends}{3.5pt}
\newcommand{\hookthickness}{0.7pt}
\newcommand{\hook}{\mathop{\hbox{%
\rule{\hookends}{\hookthickness}%
\rule{\hookthickness}{\hookheight}%
\hspace{-\hookthickness}%
\rule[\hookheight]{\hookends}{\hookthickness}%
}}}
\begin{document}
$A \hook B$
\end{document}


If you think it should be longer, taller, narrower, etc., you can adjust the parameters \hookheight, \hookthickness, and \hookends (the last one controls the lengths of the knobs). It may also be useful to adjust the spacing on either side.

With these settings, it looks like this:

For the fraction operator, I was able to adopt a similar approach. Once again, you'll likely have to twiddle it to get the height/spacing/thickness you want, especially if you're using a different font. Additionally, I calibrated it for display fractions; the spacing will be different for text fractions, though the same ideas should apply.

\documentclass{article}
\usepackage{calc}
\newcommand{\hfthickness}{0.35pt}
\newcommand{\hfseparator}{4pt}
\newcommand{\hfheight}{6pt}
\newcommand{\fracoffset}{2.35pt}
\newcommand{\hookfrac}[2]{%
\rule[\fracoffset]{\hfthickness}{\hfheight}
\rule[\fracoffset]{2pt+\hfseparator}{\hfthickness}
\hspace{-2pt}
\frac{#1}{#2}%
\hspace{-2pt}
\rule[\fracoffset]{2pt+\hfseparator}{\hfthickness}
\rule[-\hfheight+\fracoffset+\hfthickness]{\hfthickness}{\hfheight}
}
\begin{document}
$\hookfrac{A}{B} = \hookfrac{\int_X A^2 + BX + C}{\sqrt X}$
\end{document}


It looks like this.

Once again, there are a bunch of parameters you can edit: \hfthickness controls the thickness of the knobs, \hfseparator determines how far they extend past the fraction, \hfheight determines the height of the knobs, and \fracoffset is used to move them vertically, to align them with the fraction bar.

There may a better or more general way to do this, but I don't know.

• Great, any idea what to do with the fraction next? The rules would have to change position with the endpoints and height of the bar ... – Guido Jorg Oct 21 '15 at 3:08
• I'm working on it! What precisely do you mean by "height of the bar?" – Arun Debray Oct 21 '15 at 3:13
• If I put an integral in the denominator the fraction bar starts higher, because B is larger now, and the rules starting at its endpoints would have to rise with it, that's all. Same if B is smaller. We have to detect the coordinates of the fraction in x,y, to position the rules, right? It's can't be relative A with some downward shifts, because A can change in size too. It might be larger or smaller depending on the relation. – Guido Jorg Oct 21 '15 at 3:24
• Ok! I just posted a potential solution. If I understand you correctly, my solution works for this (I tested it with \displaystyle integrals in place of either of A and B and both). To the best of my understanding, the fraction bar is a fixed baseline in display math. If this isn't working for you, by all means let me know what goes wrong. – Arun Debray Oct 21 '15 at 3:29
• Ah, I see what went wrong. There was a missing } in the line \rule[-\hfheight+\fracoffset+\hfthickness]{\hfthickness}{\hfheight}. I've edited the post to fix it; does it work now? – Arun Debray Oct 21 '15 at 3:47