Forum archive 2000-2006

Michael Gage - display_matrix macro problems

Michael Gage - display_matrix macro problems

by Arnold Pizer -
Number of replies: 0
inactiveTopicdisplay_matrix macro problems topic started 9/7/2003; 10:11:11 AM
last post 9/9/2003; 12:07:51 PM
userMichael Gage - display_matrix macro problems  blueArrow
9/7/2003; 10:11:11 AM (reads: 1554, responses: 5)
Hi,

I have a question for the experts at using the display_matrix command.

The output I get for the snippet of code below typesets ok on some tex implementations, but not on others -- in particular it doesn't work on the two pdflatex installations that I have tried. The problem is one of introducing extra math delimiters inside a matrix.

Here is the snippet:



BEGIN_TEXT



...



\{ mbox( display_matrix([['\(x\)'], ['\(y\)'], ['\(z\)']]), '\(=\)', ans_array(3,1,5), '\(+\)',
ans_array_extension(3,1,5), '\(s\) \(+\)', ans_array_extension(3,1,5), '\(t\).' ) \}



END_TEXT



Here is the TeX code produced (in hardcopy mode):

 

\(\displaystyle\left(\begin{array}{c} 
\(x\) \cr
\(y\) \cr
\(z\) \cr
\end{array}\right)\)



\(=\)



\(\displaystyle\left(\begin{array}{c}
\mbox{\parbox[t]{3ex}{\hrulefill}} \cr
\mbox{\parbox[t]{10pt}{\hrulefill}}\hrulefill\quad \cr
\mbox{\parbox[t]{10pt}{\hrulefill}}\hrulefill\quad \cr
\end{array}\right)\)
\(+\)\(\displaystyle\left(\begin{array}{c}
\mbox{\parbox[t]{10pt}{\hrulefill}}\hrulefill\quad \cr
\mbox{\parbox[t]{10pt}{\hrulefill}}\hrulefill\quad \cr
\mbox{\parbox[t]{10pt}{\hrulefill}}\hrulefill\quad \cr
\end{array}\right)\)
\(s\) \(+\)\(\displaystyle\left(\begin{array}{c}
\mbox{\parbox[t]{10pt}{\hrulefill}}\hrulefill\quad \cr
\mbox{\parbox[t]{10pt}{\hrulefill}}\hrulefill\quad \cr
\mbox{\parbox[t]{10pt}{\hrulefill}}\hrulefill\quad \cr
\end{array}\right)\)
\(t\).



The problem can be seen in the first array environment. The entries are automatically in math mode, since the entire line is in math mode, and the extra math mode symbols \( \) are redunant. Apparently some tex implementations ignore the extra math mode symbols since I don't always get errors. pdflatex issues an error message and as far as I can determine from the Latex manual and "math into latex", pdflatex is following the specs.

Simply removing the math delimiters in the call to display_matrix fixes the TeX problem, but then the screen display is not what I would expect.

I'd appreciate some guidance from those who have been working more extensively with the display_matrix macro as to how to proceed.

Thanks.

--Mike

P.S. The problem may actually lie within \mbox. As I understand it display_matrix() is supposed to be used OUTSIDE a math environment (as opposed to display_matrix_mm)

In the snippet above mbox() appears to be creating a math mode for its contents.

 

<| Post or View Comments |>


userMichael Gage - Re: display_matrix macro problems  blueArrow
9/7/2003; 11:12:31 AM (reads: 1729, responses: 0)
My preliminary conclusion, on reading through the code, is that elements processed in dm_mat_row() in HTML_tth, HTML_dpng modes should be surrounded by \( \) delimiters.

Then display_matrix() should be called with arguments which do not have math mode delimiters. This makes display_matrix behave essentially the same as the array environment in TeX.

This makes the TeX processing straightforward and consistent. When using tables to simulate TeX in the dvipng mode adding the math mode delimiters makes the macro imitate the array environment as closely as possible.

--Mike

<| Post or View Comments |>


userJohn Jones - Re: display_matrix macro problems  blueArrow
9/7/2003; 6:21:29 PM (reads: 1731, responses: 0)
Hi,

I think your analysis of the situation is right.  To put it in other terms -
currently display_matrix() leaves its elements alone.  In tex/pdf situations, this means that they end up inside a matrix and are typeset in math mode.  In html based modes, they are single entries in a table, which are not put in math mode.  To fix this, one could go either way:
  • one approach would be to require math mode to be explicitly asked for.  This would be accomplished by setting all entries of the matrix (in LaTeX-based modes) inside an \mbox.  We currently get this behaviour in html-based modes.
  • the other way to get uniformity is to do just what you suggest - have display_matrix put all matrix entries in math mode by default.  This currently the behaviour in LaTeX-based modes.
The downside to the first approach is that you would have to explicitly ask for math mode as you had in the example above, which makes for more cumbersome problem writing.

The only downside I can think of to the second alternative is that matrix entries which could be left plain (like numbers) are going to become images of those numbers. 

If there is a consensus, I will try to make the change.

John

<| Post or View Comments |>


userMichael Gage - Re: display_matrix macro problems  blueArrow
9/7/2003; 6:50:53 PM (reads: 1742, responses: 0)
Would the second alternative prevent one from placing ans_rules inside a display_matrix? If so, that
probably makes the first alternative preferable.  I still have not studied the code deeply, so I am happy
to defer to your judgment on this.

--Mike

<| Post or View Comments |>


userJohn Jones - Re: display_matrix macro problems  blueArrow
9/8/2003; 10:10:34 PM (reads: 1745, responses: 0)
The second alternative is not viable for just the reason you give.   Answer rules inside the matrix would not mix with math mode on every entry.  I just uploaded a version which impliments the first alternative (\mbox around every entry).  On my test case (which was only mildly complicated), it worked with latex, vlatex, and pdflatex.

Let me know if there are problems.

John

<| Post or View Comments |>


userArnold K. Pizer - Re: display_matrix macro problems  blueArrow
9/9/2003; 12:07:51 PM (reads: 1717, responses: 0)

For those following this discussion note that there is a version of display_matrix() that should be used within math mode; it is called display_matrix_mm().  Here's the documentation from within PGmatrixmacros.pl

Arnie

    display_matrix produces a matrix for display purposes.  It checks whether
          it is producing LaTeX output, or if it is displaying on a web page in one
          of the various modes.  The input can either be of type Matrix, or a
          reference to an array.

          Entries can be numbers, Fraction objects, bits of math mode, or answer
    boxes.  An entire row can be replaced by the string 'hline' to produce
    a horizontal line in the matrix.

          display_matrix_mm functions similarly, except that it should be inside
          math mode.  display_matrix_mm cannot contain answer boxes in its entries.
          Entries to display_matrix_mm should assume that they are already in
          math mode.

          Both functions take an optional alignment string, similar to ones in
          LaTeX tabulars and arrays.  Here c for centered columns, l for left
          flushed columns, and r for right flushed columns.

          The alignment string can also specify vertical rules to be placed in the
          matrix.  Here s or | denote a solid line, d is a dashed line, and v
          requests the default vertical line.  This can be set on a system-wide
          or course-wide basis via the variable $defaultDisplayMatrixStyle, and
          it can default to solid, dashed, or no vertical line (n for none).

          The matrix has left and right delimiters also specified by
          $defaultDisplayMatrixStyle.  They can be parentheses, square brackets,
        braces, vertical bars, or none.  The default can be overridden in
          an individual problem with optional arguments such as left=>"|", or
          right=>"]".

    You can specify an optional argument of 'top_labels'=> ['a', 'b', 'c'].
    These are placed above the columns of the matrix (as is typical for
    linear programming tableau, for example).  The entries will be typeset
    in math mode.

    Top labels require a bit of care.  For image modes, they look better
    with display_matrix_mm where it is all one big image, but they work with
    display_matrix.  With tth, you pretty much have to use display_matrix
    since tth can't handle the TeX tricks used to get the column headers
    up there if it gets the whole matrix at once.

 

<| Post or View Comments |>