0

If I enable calc-embedded mode (C-x * e) in a LaTeX document (latex mode by default) when the point is in the math environment of the document below:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\newcommand*{\evalto}{}
\renewcommand*{\to}{=}
\begin{math}
[[ a, b ][ c, d ]] * [[x][y]]   =>
\end{math}
\end{document}

calc embedded produces the following code

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\newcommand*{\evalto}{}
\renewcommand*{\to}{=}
\begin{math}
\evalto \begin{pmatrix} a & b \\ c & d \end{pmatrix} \begin{pmatrix} x \\ y \end{pmatrix} \to \begin{pmatrix} a x + b y \\ c x + d y \end{pmatrix}
\end{math}
\end{document}

which perfectly render the desired output.

Produit matriciel

But this is not the case if I want to activate the latex 2 display mode to have a prettier source code:

% [calc mode: language: (latex 2)]
\begin{math}
\evalto \begin{pmatrix} \times \begin{pmatrix} \to \begin{pmatrix}
        a & b \\               x \\                a x + b y \\ 
        c & d                  y                   c x + d y
        \end{pmatrix}          \end{pmatrix}       \end{pmatrix}
\end{math}

Which does not render the desired output. So I have to move rectangular data to get it.

Is there a way to get the correct output in an easy way?

1 Answer 1

1

This is documented behaviour. From section 7.8.3 of the Calc manual:

If you invoke ‘d T’ or ‘d L’ with an argument of 2 or −2, then matrices will be displayed in two-dimensional form, such as

 \begin{pmatrix}
 a & b \\
 c & d
 \end{pmatrix}

This may be convenient for isolated matrices, but could lead to expressions being displayed like

 \begin{pmatrix} \times x
 a & b \\
 c & d
 \end{pmatrix}

While this wouldn’t bother Calc, it is incorrect LaTeX. (Similarly for TeX.)

3
  • That's exactly what I complained about. Probably I expressed myself badly. English is not my mother tongue. I am looking for a solution to avoid having to edit the code produced by Calc.
    – gigiair
    Feb 2, 2022 at 17:50
  • I think the point is that latex 2 is inappropriate for yr use-case. Source code is not prettier if it is incorrect ;-) Feb 2, 2022 at 18:27
  • I know that. My example is a 2x2 matrix, but what about a much larger matrix? I have some tricks to get around this difficulty, for example moving the code around with copying rectangles. But it's a bit boring. Probably I can compose some macro.
    – gigiair
    Feb 2, 2022 at 18:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.