4

Writing fractions using different syntax would sometimes be useful, instead of using \frac{ab}{cd}, I would prefer to write something like \frac{ab⌂cd} where the Unicode is the }{.

n.b., I don't want to mess with the \frac definition, but rather something like \newcommand{\myfrac}[2]{#1⌂#2}

Approach-My understanding of TeX is limited, but I think I can use catcode to do this, My understanding is that:

  • \catcode `@=2 is equivalent to }
  • \catcode `@=1 is equivalent to {

However just writing

\catcode`\⌂=\active
\def ⌂{ \catcode `@=2 \catcode `@=1 }
Joseph Wright
  • 259,911
  • 34
  • 706
  • 1,036
georg
  • 369
  • You can do simpler: \def\myfrac#1⌂#2{\frac{#1}{#2}}. – Eddy_Em Jan 23 '13 at 07:05
  • @Eddy_Em: But then you would still need to introduce grouping braces like \myfrac25⌂{36} because \myfrac25⌂36 would be displayed as (25/3)6. – bodo Jan 23 '13 at 07:12
  • 1
    I add an answer, but be careful in choosing of last symbol (apostrophe in this case): it shouldn't be in argument of \myfrac. – Eddy_Em Jan 23 '13 at 07:16
  • Maybe something like: \catcode\⌂=13 \let⌂\over $ {1⌂2} $ \bye`? – morbusg Jan 23 '13 at 08:11

1 Answers1

8

I have koi8-r locale & don't work with unicode, so instead of I'll use |:

First define a command:

\makeatletter
\def\myfrac@#1|#2'{\frac{#1}{#2}}
\def\myfrac#1{\myfrac@#1'}
\makeatother

Then use it:

example: $\myfrac{10|20}$
Eddy_Em
  • 1,405
  • Thanks, this works perfectly! However, I am wondering if there is a way to do this along the lines I specified..it would be nice to know my way around catcode – georg Jan 23 '13 at 07:19
  • @georgraba Catcodes have nothing to do with this: see http://tex.stackexchange.com/questions/16410/what-are-category-codes for a starter on them. – Joseph Wright Jan 23 '13 at 07:21