1

I have this matrix in LyX:

enter image description here

LyX generates this latex code:

\documentclass[english]{article}
\usepackage[T1]{fontenc}
\usepackage[latin9]{inputenc}
\usepackage{amsmath}
\usepackage{babel}

\begin{document}
  \begin{align*}
    \mathcal{M}(T)=
    \begin{pmatrix}
      &  & A_{1,k}\\
      &  & \vdots\\
      &  & A_{m,k}
    \end{pmatrix}
  \end{align*}
\end{document}

I'd like to extend the matrix to this:

enter image description here

How can I do using LyX GUI?

8
  • Does it have to be via amsmath?
    – MS-SPO
    Jan 22 at 14:45
  • 2
    The nicematrix package allows you to add exterior rows and columns
    – bonk
    Jan 22 at 14:54
  • @MS-SPO: I've no constraint except it must be done using LyX UI.
    – mins
    Jan 22 at 15:16
  • 1
    Then see e.g. here: tex.stackexchange.com/questions/59517/…
    – MS-SPO
    Jan 22 at 15:22
  • Perhaps now is a good time to add your lyx-file to your question, which complies with the Latex code you posted?
    – MS-SPO
    Jan 22 at 15:51

2 Answers 2

2

Here's a way to do it with Lyx.

As far as I can see both from checking out Lyx 2.3.7, and internet search, there are no GUI-action prepared for what you want to do. I tried two things.

First, which is close to what you want to do by mouse:

  • M=
  • Alt + M (
  • insert Matrix 3*3
  • which creates the first row
  • as you can see, it wraps an array environment into math mode ($ .. $)

lyx main

Second: There was a similar question, which was answered in Latex-terms. Actions:

  • insert TEX code (crtl + L)
  • put math mode $$ or [ ] depending on your goal
  • copy said code (or write it down here by hand) into the red frame

What's missing is specifying the package:

  • Document/Settings
  • LaTeX Preamble
  • enter the package call from said answer

usepackage

From watching the LaTeX (pdflatex) preview window I know, I copied as it should be.

Compiling (ctrl + r, and you're done) I have to do in a different way, as my setup is still quite immature:

  • save
  • File/Export/Latex (pdflatex)
  • open the new .tex file in my current Latex environment (Texmaker)
  • compile

There I am:

result

Lyx-file: This is how Lyx stores results from GUI-actions; past this code into a file, say yours.lyx, and open it with Lyx to see my edits:

#LyX 2.3 created this file. For more info see http://www.lyx.org/
\lyxformat 544
\begin_document
\begin_header
\save_transient_properties true
\origin unavailable
\textclass article
\begin_preamble
\usepackage[renew-dots,renew-matrix]{nicematrix}
\end_preamble
\use_default_options true
\maintain_unincluded_children false
\language english
\language_package default
\inputencoding auto
\fontencoding global
\font_roman "default" "default"
\font_sans "default" "default"
\font_typewriter "default" "default"
\font_math "auto" "auto"
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_osf false
\font_sf_scale 100 100
\font_tt_scale 100 100
\use_microtype false
\use_dash_ligatures true
\graphics default
\default_output_format default
\output_sync 0
\bibtex_command default
\index_command default
\paperfontsize default
\spacing single
\use_hyperref false
\papersize default
\use_geometry false
\use_package amsmath 1
\use_package amssymb 1
\use_package cancel 1
\use_package esint 1
\use_package mathdots 1
\use_package mathtools 1
\use_package mhchem 1
\use_package stackrel 1
\use_package stmaryrd 1
\use_package undertilde 1
\cite_engine basic
\cite_engine_type default
\biblio_style plain
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
\justification true
\use_refstyle 1
\use_minted 0
\index Index
\shortcut idx
\color #008000
\end_index
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\paragraph_indentation default
\is_math_indent 0
\math_numbering_side default
\quotes_style english
\dynamic_quotes 0
\papercolumns 1
\papersides 1
\paperpagestyle default
\tracking_changes false
\output_changes false
\html_math_output 0
\html_css_as_file 0
\html_be_strict false
\end_header

\begin_body

\begin_layout Standard
M=
\begin_inset Formula $\left(\begin{array}{ccc}
 & a & b\\
c & 1 & 2\\
d & 3 & 4
\end{array}\right)$
\end_inset


\end_layout

\begin_layout Standard
\begin_inset ERT
status open

\begin_layout Plain Layout

$M=
\backslash
begin{pmatrix}[first-row,first-col]
\end_layout

\begin_layout Plain Layout

  & a & b 
\backslash

\backslash

\end_layout

\begin_layout Plain Layout

x & 1 & 2 
\backslash

\backslash

\end_layout

\begin_layout Plain Layout

y & 3 & 4
\end_layout

\begin_layout Plain Layout


\backslash
end{pmatrix}$
\end_layout

\end_inset


\end_layout

\end_body
\end_document

Compared to Texmaker or any other Latex setup

All I then need to do is:

  • creating a new file
  • copy code from said answer (or type it manually)
  • save
  • compile

Time and again, GUIs seem to be neat, but add a lot of new complexity, often paired with little flexibility ... while knowing Latex by heart, having a nice supporting editor and some command line based compille will be fast, less error prone, keep you going.

texmaker

1
  • +1, but it seems you have redefined the dots, the best I can get is that.
    – mins
    Jan 23 at 0:32
2

An alternative to @MS-SPO solution without using an additional package, and then no need to create/edit the preamble file. The code being not standard for LyX (there is no dedicated menu entry), it must be entered manually, i.e. using the so-called ERT box.

$
\bordermatrix {
       & v_1 & \dots   & v_k & \dots & v_n \cr
w_1    &     &         & A_{1,k} \cr
\vdots &     &         & \vdots \cr
w_m    &     &         & A_{m,k} \cr
}
$

enter image description here

There is a slight problem in the vertical alignment of the vertical headers, but I didn't find the documentation for \bordermatrix and don't know if there are options to fix it without adding an extra space.

2
  • Right. Did you change your mind? tex.stackexchange.com/questions/707657/…
    – MS-SPO
    Mar 4 at 18:20
  • 1
    @MS-SPO: Windows implementation of this Linux application is not optimized, changing the preamble in Lyx Windows is definitely not straightforward due to folder access authorizations. If manual code is not wysiwyg, preamble change is a headache. This solution is the lesser evil, this is the one I would recommend to others.
    – mins
    Mar 5 at 9:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .