Forum archive 2000-2006

Kenneth Appel - TeX and Matrices

Kenneth Appel - TeX and Matrices

by Arnold Pizer -
Number of replies: 0
inactiveTopicTeX and Matrices topic started 11/19/2004; 3:34:33 PM
last post 11/22/2004; 12:27:35 PM
userKenneth Appel - TeX and Matrices  blueArrow
11/19/2004; 3:34:33 PM (reads: 3379, responses: 8)
I would appreciate any explanation of this phenomenon.

In a problem I have the following TeX code

Convert the permutation ( left(matrix{1&2&3&4&5&6&7cr $a[0] & $a[1] & $a[2] & $a[3] & $a[4] & $a[5] & $a[6]cr}right) ) $BR to standard cycle form (leave no spaces in your answer)

When I use jsMath it prints the intended two row matrix for the permutation. (enclosed by tall parentheses.)

When I use images it prints a single row with the fourteen items enclose by parentheses

Any explanation of why this happens would be greatly appreciated. Ken Appel kia@oregano.unh.edu

<| Post or View Comments |>


userJohn Jones - Re: TeX and Matrices  blueArrow
11/19/2004; 5:36:30 PM (reads: 3587, responses: 0)
I am not familiar with \matrix as a LaTeX command. I guess it is a plain TeX command. Images for image mode are generated with LaTeX with a collection of macros added. Maybe there is a conflict there. How does it look in hardcopy?

John

PS It would be possible for others to try the code you posted via copy and paste if you use "pre" tags around it.

<| Post or View Comments |>


userDavide P. Cervone - Re: TeX and Matrices  blueArrow
11/20/2004; 9:02:24 AM (reads: 3583, responses: 0)
Image mode calls LaTeX to process the mathematics, and it includes the amsmath package by default. It turns out that this package redefines \matrix and \pmatrix to generate errors (suggesting the use of the matrix and pmatrix LaTeX environments instead.) Image mode ignores errors in the TeX code, however, and so it keeps on trying to process the code. Since it has never entered the \halign that is part of \matrix, the & and \cr also produce errors (that are ignored), and the effect is that you get the numbers concatenated to each other as though there were nothing in between them.

There are several possible solutions. One would be to use \begin{array} and \end{array} rather than \matrix{}, as in

 

  \left(
\begin{array}{ccccccc}
1& 2& 3& 4& 5& 6& 7\\
$a[0] & $a[1] & $a[2] & $a[3] & $a[4] & $a[5] & $a[6]\\
\end{array}
\right\)

Ideally you would use the pmatrix or matrix environments, but jsMath doesn't know about these; I'll have to add them in.

Alternatively, you can modify webwork2/lib/WeBWorK/Constants.pm to include

 

    {\catcode`\@=\catcode`\A
\gdef\matrix@check#1%
{\@xp\ifx\csname\@currenvir\endcsname#1\else\@@matrix@check@@#1\fi}
\gdef\@@matrix@check@@#1\fi#2#3%
{#2#3\csname end\expandafter\@gobble\string#1\endcsname}}

in $WeBWorK::PG::ImageGenerator::TexPreamble just before the \begin{document}. This disables the check for "old style" \pmatrix and \matrix commands and allows them to be processed normally.

Hope this helps.

Davide

<| Post or View Comments |>


userKenneth Appel - Re: TeX and Matrices  blueArrow
11/20/2004; 9:08:22 AM (reads: 3555, responses: 0)
Davide Thank you. I read John Jones message first and decided that my 20 year exclusive use of Knuth's book had to come to an end so looked for the comparable latex code, which is exactly what you supplied, and it worked perfectly Ken Appel

<| Post or View Comments |>


userJohn Jones - Re: TeX and Matrices  blueArrow
11/20/2004; 10:00:45 AM (reads: 3543, responses: 0)
Hi again,

I should have also mentioned that webwork has commands for making matricies which should do the right thing in different modes. Since there are no answer boxes in this matrix, you could use

 ( display_matrix_math_mode([1,2,3,4,5,6,7], 
[$a[0], $a[1], $a[2], $a[3], $a[4], $a[5], $a[6]] )
There are optional arguments to adjust the alignment of columns, or for the side delimiters. To use it, you need to load PGmatrixmacros.pl. For documentation run perldoc on PGmatrixmacros.pl.

John

<| Post or View Comments |>


userMichael Gage - Re: TeX and Matrices  blueArrow
11/20/2004; 10:36:41 AM (reads: 3572, responses: 0)
Hi,

This is probably redundant at this point, but here is my summary of WeBWorK's behavior in displaying matrices.

 



DOCUMENT() ;



loadMacros(
PG.pl,
PGbasicmacros.pl,
PGchoicemacros.pl,
PGanswermacros.pl,
PGauxiliaryFunctions.pl,
PGdiffeqmacros.pl,
PGmatrixmacros.pl
) ;
############



TEXT(beginproblem());
@a = (0,1,2,3,4,5,6,7,8);



@b= (1,2,3,4,5,6,7,8, 9);




BEGIN_TEXT



Displays in jsMath but not in images mode (native TeX)
$PAR
( left(matrix{1&2&3&4&5&6&7\
$a[0] & $a[1] & $a[2] & $a[3] & $a[4] & $a[5] & $a[6]cr}right) )
$PAR
Displays in images mode but not in jsMath (LateX commands)
$PAR
( left(begin{matrix}1&2&3&4&5&6&7\
$a[0] & $a[1] & $a[2] & $a[3] & $a[4] & $a[5] & $a[6]crend{matrix}right) )
$PAR
Displays in both modes
(see http://webhost.math.rochester.edu/webworkdocs/docs/pglanguage/pod/pgmatrixmacros#display_matrix)
$PAR
{ display_matrix([~~@a,~~@b]) }




END_TEXT



ENDDOCUMENT();

Display in jsMath mode:

jsMath_mode.png

Display in image mode: image_mode.png

<| Post or View Comments |>


userDavide P. Cervone - Re: TeX and Matrices  blueArrow
11/20/2004; 12:20:26 PM (reads: 3594, responses: 0)
I have updated jsMath to include the missing LaTeX environments for matrices. These include matrix, pmatrix, bmatrix, Bmatrix, vmatrix, and Vmatrix, which give matrices with no parens, round parens, brackets, curly braces, vertical bars, and double vertical bars, respectively. It has been updated in the CVS repository.

One caveat about the display_matrix command: the entries are not automatically in math mode, so if you look carefully at Mike's examples above, you'll see the numbers look different in the lower three matrices from the two above them. That's not a complaint, just a detail to be aware of. (I'm sure that it is set up that way so that you can have answer rules within the matrices generated by display_matrix; they are not allowed in math mode.)

Davide

<| Post or View Comments |>


userArnold K. Pizer - Re: TeX and Matrices  blueArrow
11/22/2004; 10:43:41 AM (reads: 3577, responses: 0)
Let me add an additional comment on Davide's caveat. Davide is definitely correct that with display_matrix the entires are not automatically put in math mode. The reason is, as Davide surmises, that with display_matrix you can put in answer rules and also math [using e.g. \( sin(x) \)]. If all your entries are mathematical expressions, you should use display_matrix_math_mode (or the equivalent display_matrix_mm) as in John Jones' example above.

Arnie

<| Post or View Comments |>


userJohn Jones - Re: TeX and Matrices  blueArrow
11/22/2004; 12:27:35 PM (reads: 3546, responses: 0)
Hi,

When I mentioned display_matrix_mm, I was going on what I expected that it did, and not so much on what it really does (it has been a long time since I looked at it). At the moment, I can't make it do anything useful for matricies with formulas in it (or any bits of math mode in it). On the other hand, display_matrix was working correctly (where you have to explicity put entries in math mode as described above, e.g., '\( \sin x\)').

Maybe I should change it so that it does not mbox its entries? Then it will work more as expected. Since it is hard to make it handle formulas now, presumably this won't break existing problems?

John

<| Post or View Comments |>