Groff Eqn - How to do higher roots (cube root, etc)

291 views Asked by At

Does someone know how to do higher roots (cube roots, 4th roots, etc) in groff eqn? Been searching around the docs and cant seem to find the answer

3

There are 3 answers

1
meuh On

In simple cases you can use a subscripted number before the root sign:

"" sup 3 sqrt x

but this does not look too good depending on the equation:

1 over { "" sup 3 { sqrt {ax sup 2 +bx+c} } }

An alternative is to use left-justified pile, which also has a large gap:

1 over { lpile { { size -8 3 } above { sqrt {ax sup 2 +bx+c} } } }

so often the best is to use the eqn local motion commands, up, back, size to play with the position to get the wanted result:

1 over { { up 90 size -8 3 } back 30 { sqrt {ax sup 2 +bx+c} } }

enter image description here

0
Gavin Freeborn On

I would recommend using eqn macros like this

.EQ
define exp % "" sup fwd 30 %
define cube % "" sup fwd 30 3 sqrt %
define root % { "" sup fwd 30 $1 sqrt $2 } %

exp 3 sqrt 11
cube 11
root(3,11)
.EN
0
tavo-wasd On

I was able to make a simple macro for nth index roots, this way:

.EQ
root {x} sup 3
.EN

example-roots-image

Just add this wherever in your code, before using it:

.EQ
define root % sqrt special Rt %
.EN
.de Rt
.  ds 0s \
\Z'\h'0.3n'\\*(0s'\
\h'-0.1n-\\n(0hu'\
\v'\\n(0du-1n'
..

And then to use it:

.EQ
root {x} sup 3
.EN

It won't be very pretty always, see: ugly-roots-image

But for 1-digit indexes and regular roots it should be fine. The ugly roots is more of a general problem with groff anyway.