Augmented matrices

46 views
Skip to first unread message

Sean Fitzpatrick

unread,
Jan 28, 2020, 1:06:43 AM1/28/20
to PreTeXt support
With all the PreTeXt linear algebra books out there: does anyone have a good macro for an augmented matrix?
Here I have in mind the style where there's a vertical bar representing the = sign, separating constants from coefficients.

I have a LaTeX macro that works well, built on an array environment. I define

\newenvironment
{amatrix}[1]{%
  \left[\begin{array}{@{}*{#1}{c}|c@{}}
}{%
  \end{array}\right]
}

But I recall that use of array is discouraged in PreTeXt -- and testing suggests one reason:
in LaTeX the above gives me one vertical rule, where I expect it. But MathJax puts one between every column!

I can always do something like
\left[\begin{matrix} ... \end{matrix}\right\vert \left.\begin{matrix} ...\end{matrix}\right]

but this is somewhat cumbersome compared to LaTeX, where I'd do
\begin{amatrix}{n} ... \end{amatrix}

This lets me include the constant term in the same matrix/row as the coefficients, which is a little easier when doing things like step-by-step row operations.
Anyone with clever solutions they're willing to share?

(Of course, I could give up on the macro and do a manual array each time. But are there other reasons to avoid array?)

Alex Jordan

unread,
Jan 28, 2020, 2:28:29 AM1/28/20
to pretext...@googlegroups.com
But MathJax puts one between every column!

I think that issue is that MathJax does not understand this construction:
*{#1}{c}
and it turns
*{#1}{c}|c
into
c|c
and then repeats the "|c" for as many columns as are needed given how many &s you have. (Where regular LaTeX will just choke if there is a mismatch, MathJax is trying to salvage the situation by reusing the last column type.) I just posted about this on the MathJax users group.

If they make the *{count}{pattern} construction work, then great. Otherwise, instead of trying to pass a number, you could just pass an actual alignment string with so many "c"s. Like:

\newenvironment{amatrix}[1][ccc|c]{\left[\begin{array}{#1}}{\end{array}\right]}

$\begin{amatrix}
    1 & 2 & 4 & 8 \\
    16 & 32 & 64 & 128 \\
    256 & 512 & 1024 & 2048
\end{amatrix}$

In this example, I made the default optional argument be "ccc|c", for what may be the most common alignment string. But you could do like this and replace the default:

$\begin{amatrix}[cc|cc]
    1 & 2 & 4 & 8 \\
    16 & 32 & 64 & 128 \\
    256 & 512 & 1024 & 2048
\end{amatrix}$

This whole approach doesn't seem semantic. Because you'd really like a way to declare the left columns separately from the right columns. This is a little better, but no longer an environment:

\newcommand{\augmentedmatrix}[2]{\left[\;\begin{matrix}#1\end{matrix}\right.\;\left\rvert\;\begin{matrix}#2\end{matrix}\;\right]}

$\augmentedmatrix{
1&2&4\\
16&32&64\\
256&512&1024
}{
8\\
128\\
2048
}$

Although still not perfect, because I think you would want the information to come one column at a time if it is an augmented matrix. And then that's not how LaTeX arrays work.

--
You received this message because you are subscribed to the Google Groups "PreTeXt support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pretext-suppo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pretext-support/52cdc1f6-d5a8-4ca1-9b8a-3e6bd7852d0e%40googlegroups.com.

Sean Fitzpatrick

unread,
Jan 28, 2020, 9:09:42 AM1/28/20
to pretext...@googlegroups.com
Thanks. I've long been in the habit of reading information in by row, since that's how LaTeX expects the input. The macro I used (probably cribbed from Stack Overflow long ago) extends that workflow to augmented matrices.

Does [1][ccc|c] let me override the ccc|c layout with an argument? I didn't know that syntax worked. (I would have expected to use something like \begin{array}[#1] and then input \begin{amatrix}{ccc|c}.)

This isn't too bad; it just changes the argument I have to pass from a number (how many columns in the coefficient matrix) to the column layout.

I just want to make sure there's no reason not to use array in math mode.

Rob Beezer

unread,
Jan 28, 2020, 10:44:19 AM1/28/20
to pretext...@googlegroups.com
On 1/28/20 6:09 AM, Sean Fitzpatrick wrote:
> I just want to make sure there's no reason not to use array in math mode.

"2D" mathematics, like "array" and "bmatrix" are not yet full implemented by
Speech Rule Engine for Nemeth braille output, but I don't think there is a
distinction there.

Sometimes "array" is used where maybe "md/mrow" or "tabular" would be better.

For example, is a Cayley table a monolithic "array" or a "tabular" full of
math? I could argue both sides, mathematically and PreTeXt-ly.

I'd vote for some variant of "matrix", "bmatrix", "pmatrix" for purely semantic
reasons. Or better a "\augmentedmatrix" matrix macro with coefficient matrix
and "vector of constants" as two arguments (which I never quite got working
years ago).

Rob

Alex Jordan

unread,
Jan 28, 2020, 11:10:57 AM1/28/20
to pretext...@googlegroups.com
I retract my \augmentedmatrix, because it is not going to look nice when, say,
the left columns are just digits, and the right column(s) have fractions.

Does [1][ccc|c] let me override the ccc|c layout with an argument?

Yes, with two bracket pairs like this, the [1] says there will be one optional
argument, and the [ccc|c] is the default value for that. So you can use
\begin{amatrix}[cc|c], or \begin{amatrix}[ccc|ccc], etc.

Btw, if it were say [2][ccc|c] then there are two arguments. The first uses the
"optional" syntax with default "ccc|c" and the second is not optional. Maybe
you could use that somehow.


--
You received this message because you are subscribed to the Google Groups "PreTeXt support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pretext-suppo...@googlegroups.com.

Rob Beezer

unread,
Jan 28, 2020, 11:24:42 AM1/28/20
to pretext...@googlegroups.com
The "matrix" environment supplies no window-dressing. Might a macro smash two
together (one multi-column, the other a single column) and supply the delimiters
and the vertical bar? Just musing, not tested. Class....

Rob
> <mailto:pretext-support%2Bunsu...@googlegroups.com>.
> --
> You received this message because you are subscribed to the Google Groups
> "PreTeXt support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email
> to pretext-suppo...@googlegroups.com
> <mailto:pretext-suppo...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pretext-support/CA%2BR-jrfgkJ3eTyQ7-DHRFKPtfnhXErmp5RLUpbHoq7Q%3DSh47ow%40mail.gmail.com
> <https://groups.google.com/d/msgid/pretext-support/CA%2BR-jrfgkJ3eTyQ7-DHRFKPtfnhXErmp5RLUpbHoq7Q%3DSh47ow%40mail.gmail.com?utm_medium=email&utm_source=footer>.

Alex Jordan

unread,
Jan 28, 2020, 11:44:59 AM1/28/20
to pretext...@googlegroups.com
Might a macro smash two
together (one multi-column, the other a single column) and supply the delimiters
and the vertical bar?

This is what I proposed with the \augmentedmatrix definition I offered. But the
problem becomes when the left columns have "short" entries like integers, and
the right column(s) have "tall" entries like fractions. If the two sides are built
independently, they don't respect each other's row heights.

To unsubscribe from this group and stop receiving emails from it, send an email to pretext-suppo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pretext-support/28a13a60-2e2c-d9a4-a138-59ba82c3f253%40ups.edu.

Sean Fitzpatrick

unread,
Jan 28, 2020, 12:14:31 PM1/28/20
to pretext...@googlegroups.com
Right. So while it's not ideal for accessibility, using array ensures that everything lines up as it should.

So Alex's fist suggestion might be the way to go.
Or maybe I do:

\newenvironment{amatrix}[1]{%
  \left[\begin{array}{#1}

  \end{array}\right]
}
where the usage is like \begin{amatrix}{cc|c}.

Jane Butterfield

unread,
Jan 30, 2020, 11:42:17 AM1/30/20
to PreTeXt support
We had blind/low vision students taking math courses that involve matrices with us last year. I had a lot of conversations with our alt-text staff at the Centre for Accessible Learning (CAL) last year, regarding about four different math courses, and the darn matrices in those two courses were the worst problem for us. The tools the CAL use just read them in the most annoying way; it was hard to navigate to a particular entry. I showed them the Beezer Linear Algebra html book, and they were impressed with it, but there are still two issues I couldn’t work out how to deal with properly with PreTeXt, and the conversations fizzled a bit because they didn’t have hours to train their staff in the new tool and I couldn’t work out how to set it up for them.

One of them is this augmented matrix line, and working this out would sort out both of our linear algebra courses.

The other issue we had is for the text used in our introduction to discrete math for non-majors. One section of this course deals with markov chains in a very small way, and in that section we had a lot of decorated matrices to deal with. By that I mean they have letters above columns, or to the left of rows. They also have horizontal lines (as well as vertical ones) within the matrix, to carve it into four sub-matrices. So I’ll add this to the list of things that are (I think) currently hard/impossible to do with a matrix, but will add that the main reason I care is for screen-reader accessibility.

Sean Fitzpatrick

unread,
Jan 30, 2020, 4:15:42 PM1/30/20
to pretext...@googlegroups.com
Interesting. Perhaps we should just dispense with that line altogether? It's certainly not required, and some texts don't bother with it.

It then becomes a matter of context, rather than visual representation, to decide if a matrix is augmented or not.

(Now, the use case I'm working on is slides, so the visual representation is pretty much the whole story, but I bet life would go on if we dropped the vertical rule.)

--

David Farmer

unread,
Jan 30, 2020, 4:25:05 PM1/30/20
to pretext...@googlegroups.com

Do the MathJax people have a way to make an augmented (or a decorated)
matrix accessible to screen readers?

If they told us what to do, then I think it would be no problem for
us to craft a macro that does it in a way that is easy for authors.
> --
> You received this message because you are subscribed to the Google Groups "PreTeXt support" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> pretext-suppo...@googlegroups.com.
> To view this discussion on the web visithttps://groups.google.com/d/msgid/pretext-support/CAH%2BNcPaeLHX%2BV7%3DEAq7YQYUpuS%2BQwLtDpWW-Kiz9pwc_md%2Bmnw%40mail.gmail
> .com.
>
>

Karl-Dieter Crisman

unread,
Jan 31, 2020, 6:47:23 AM1/31/20
to PreTeXt support


On Thursday, January 30, 2020 at 4:15:42 PM UTC-5, Sean Fitzpatrick wrote:
Interesting. Perhaps we should just dispense with that line altogether? It's certainly not required, and some texts don't bother with it.

It then becomes a matter of context, rather than visual representation, to decide if a matrix is augmented or not.

(Now, the use case I'm working on is slides, so the visual representation is pretty much the whole story, but I bet life would go on if we dropped the vertical rule.)


it does, but it's %*$^& annoying. One of the most popular LA textbooks does not use it for some reason for augmented matrices, and one has a dickens of a time getting students to decide about whether something is in echelon form or not without that vertical line.  

And now imagine block matrices.  Don't we kind of need lines like that to even talk about block matrices - for instance, for demonstrating the use of homogeneous coordinates for affine transformations of graphics?  

Obviously if MathJax can't support this, it may all be moot, but I will note that 

A = matrix(QQ, 2, 2, [3,9,6,10])
B = block_matrix([ [A, -A], [~A, 100*A] ])
latex(B)

gives

A = matrix(QQ, 2, 2, [3,9,6,10])
B = block_matrix([ [A, -A], [~A, 100*A] ])
latex(B)

which seemed to render fine at https://www.mathjax.org/#demo   So

$\left(\begin{array}{rrr|r}
3 & 9 & -3 & -9 \\
6 & 10 & -6 & -10 \\
\end{array}\right)$

could be used to do an augmented matrix?  But of course earlier in this discussion people suggested array is not the right thing to use for PTX rationales, so maybe I just rehashed everything to no purpose ...

Sean Fitzpatrick

unread,
Jan 31, 2020, 9:21:32 AM1/31/20
to pretext...@googlegroups.com
It seems maybe the only issue with array is accessibility in MathJax (and maybe earlier versions didn't render them properly? Seems ok now as long as you don't get too fancy.)

Probably there needs to be semantic markup (like block matrix) that works for non sighted readers.

Right now we expect readers to infer the block structure from visual cues.
That's no good if you can't see.

We'd need input from the accessibility people at MathJax to come up with something, I think.

--

Rob Beezer

unread,
Jan 31, 2020, 11:38:23 PM1/31/20
to pretext...@googlegroups.com
Dear Jane,

Thanks for the discussion around blind readers and what I generally have been
calling "2D math". As you know there is a group that is well along on a
conversion of PreTeXt to braille. Exactly these sorts of things are some of the
remaining hurdles. Our hope is that MathJax and Speech Rule Engine will be able
to make some concrete progress soon, both for brailler and for speech. So time
might get your courses sorted.

"alt-text staff"? Really? None of us have a real idea about best practices.
Do you really have experts there?

Rob

Rob Beezer

unread,
Jan 31, 2020, 11:40:22 PM1/31/20
to pretext...@googlegroups.com
On 1/31/20 3:47 AM, Karl-Dieter Crisman wrote:
> But of course earlier in this
> discussion people suggested array is not the right thing to use for PTX
> rationales

Not exactly. Sometimes there might be alternatives to "array" that are better
all-around.

Alex Jordan

unread,
Feb 1, 2020, 2:03:53 AM2/1/20
to pretext...@googlegroups.com
But of course earlier in this discussion people suggested array is not the right thing to use

Not exactly what I meant, if you are referring to my post.
It is fine for making the visual of an augmented matrix.
(And getting to the original difficulty Sean posted about,
it avoids the *{}{} construction.)

It's not semantic though. Which suggest that it will be
harder to make it fully accessible. Sometimes we have
semantic markup for these things, and even if the present
doesn't have a solution for making them accessible, at
least the semantic markup makes it more likely that a
solution will be invented at some point.

Semantic markup for augmented or block matrices at this
point in time seems to have the other problem: not leading
to something where the visual rendering looks good.
"Semantic" wants to make each block specified in isolation.
But "looking good" wants to have alignment across a row
that spans multiple blocks, and also across a column that
spans multiple blocks. These two things are at odds.
 

--
You received this message because you are subscribed to the Google Groups "PreTeXt support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pretext-suppo...@googlegroups.com.

Karl-Dieter Crisman

unread,
Feb 1, 2020, 11:49:46 AM2/1/20
to PreTeXt support


On Saturday, February 1, 2020 at 2:03:53 AM UTC-5, jordancanonical wrote:
But of course earlier in this discussion people suggested array is not the right thing to use

Not exactly what I meant, if you are referring to my post.
It is fine for making the visual of an augmented matrix.
(And getting to the original difficulty Sean posted about,
it avoids the *{}{} construction.)

It's not semantic though. Which suggest that it will be
harder to make it fully accessible. Sometimes we have
semantic markup for these things, and even if the present
doesn't have a solution for making them accessible, at
least the semantic markup makes it more likely that a
solution will be invented at some point.

Semantic markup for augmented or block matrices at this
point in time seems to have the other problem: not leading
to something where the visual rendering looks good.
"Semantic" wants to make each block specified in isolation.
But "looking good" wants to have alignment across a row
that spans multiple blocks, and also across a column that
spans multiple blocks. These two things are at odds.


Would it be possible to have some kind of alt text that had that semantic value via some custom macro in html output for PTX?  After all, nobody said we can't add something to the way we render matrices - perhaps there could be a specific "block matrix" macro (maybe not environment) that would be typeset and coded normally, but which would alert the xsl to add something semantic as alt text.

Alex Jordan

unread,
Feb 1, 2020, 12:27:07 PM2/1/20
to pretext...@googlegroups.com
"alt" is an attribute for an HTML "img". So my first thought is,
what does it mean to add alt text to some math content that
ultimately is in the page as MathJax?

My second thought is that the pain with alt text and images
is that it's not automatic. You supply the image and then you
also supply the description. People naturally fail to do all the
doubled work all the time.

Something where you make math in the regular way and
separately describe it in words would suffer the same issues.





--
You received this message because you are subscribed to the Google Groups "PreTeXt support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pretext-suppo...@googlegroups.com.

Rob Beezer

unread,
Feb 1, 2020, 2:01:31 PM2/1/20
to pretext...@googlegroups.com
On 2/1/20 9:26 AM, Alex Jordan wrote:
> My second thought is that the pain with alt text and images
> is that it's not automatic. You supply the image and then you
> also supply the description. People naturally fail to do all the
> doubled work all the time.

In the schema we make "description" *required*. And (possibly) non-empty. ;-)

Alex Jordan

unread,
Feb 1, 2020, 2:08:51 PM2/1/20
to pretext...@googlegroups.com
Third thought: making math accessible includes making it possible to navigate
the pieces within the math, so the reader can focus on "atomic" and "molecular"
portions before they fully understand the "compound". That's why the MathJax
math navigator tool is so amazing. Semantic markup of the math or very smart
heuristics on non-semantic markup of math will make that possible.



--
You received this message because you are subscribed to the Google Groups "PreTeXt support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pretext-suppo...@googlegroups.com.

Jane Butterfield

unread,
Feb 1, 2020, 3:24:58 PM2/1/20
to PreTeXt support
Rob,

I will reach out to my contacts at our Centre for Accessible Learning to see whether they can join this conversation, and to find out what they ultimately decided to do with those decorated matrices. It might be productive for both teams if we could bring you up to Victoria to chat with them in person, too; fancy a visit to sunny Victoria?

-Jane

Rob Beezer

unread,
Feb 2, 2020, 5:26:26 PM2/2/20
to pretext...@googlegroups.com
On 2/1/20 12:24 PM, Jane Butterfield wrote:
> if we could bring you up to Victoria to chat with them in person, too;
> fancy a visit to sunny Victoria?

Sunny? Really? Pretty grey and miserable here for several weeks now (until today).

Yes, a trip to Victoria would be great. Even in a drizzle. More coming to you
off-list.

Rob
Reply all
Reply to author
Forward
0 new messages