Commit Graph

3594 Commits

Author SHA1 Message Date
Jean-Marc Lasgouttes
2baa292314 Do not export the content of InsetMathBoxed as text in MathML
\boxed{} is the only box in LaTeX that contains math. It is amusing
that the example file that we had for ticket #13609 should not have
been a problem since there is no reason to force <mtext> there.

(cherry picked from commit 1186d90edf)
2024-07-24 18:26:53 +02:00
Jean-Marc Lasgouttes
458ce0fdba Fixup b29b3eb1: close <mtext> when quitting text mode
This fixes malformed documents on UserGuide export.

Related to bug #13069.

(cherry picked from commit 1385f0fddd)
2024-07-24 18:17:20 +02:00
Jean-Marc Lasgouttes
8ea0987644 Fixup b29b3eb1: fix broken xml syntax
This commit addresses two issues:

1/ the embarassing one: the member SetMode::old_text_level_ was
   declared as bool instead of int. This means that is was definitely
   not a proper backup variable!

2/ a robustness issue: replace two consecutive test for isTest() by a
   boolean veriable that is used twice. This makes sure that <mrow>
   cannot be output without the corresponding </mrow>.

Part of bug #13069.

(cherry picked from commit a268fe096a)
2024-07-24 18:17:13 +02:00
Jean-Marc Lasgouttes
b29b3eb1fc Fix crash when generating MathML with InsetMathBox
Instead of generating code and parsing it to add <mtext>...</mtext> at
the right spots, this commit honors the text mode setting that was
already present in the codebase to generate it automatically.

This is the work of two helper methods in MathMLStream:

* beforeText() notices when the stream is in text mode and that a
  <mtext> has not yet been generated. In this case it inserts it, so
  that raw text can be emitted afterwards.

* beforeTag() checks whether a <mtext> needs to be closed at this
  point, and does it if needed.

To make this work, the code now tracks the nesting level in the
stream, and compares it the what the level was when text mode has been
enabled using the SetMode helper function.

In order to avoid later bugs, member os() that allows to access the
underlying stream of MathMLStream is removed. This required many <<
operators to become friends of MathMLStream.

In InsetMathBox, rename splitAndWrapInMText() to mathmlizeHelper(),
which is not just a method that sets text mode inside a <mrow>
element.

In InsetMathFont and InsetMathHull, the explicit generation of nesting
in <mtext>...</mtext> can be removed now.

Fixes bug #13069.

(cherry picked from commit 216a6fb348)
2024-07-22 22:08:58 +02:00
Jean-Marc Lasgouttes
17bc6d05b3 Cleanup MathMLStream
This is preparatory work for fixing ticket #13069.

Remove direct accesses to the underlying stream of MathMLStream in
InsetMathChar, InsetMathSpecialChar, and in all << operators other
than MathMLStream << docstring. This will allow to add a hook later in
this operator.

Move default values of MathMLStream private members to their definition.

Get rid of line_ member, which is not used.

(cherry picked from commit fbd4b0a13f)
2024-07-22 22:06:02 +02:00
Jean-Marc Lasgouttes
b39fb17316 Force a Buffer * argument to math insets constructor
Make sure that math insets have a proper buffer. To this end, make the
Buffer* parameter of InsetMath mandatory and fix the compilation
errors that ensue.

(cherry picked from commit c013799887)
2024-07-05 12:23:59 +02:00
Jean-Marc Lasgouttes
6b54661317 Force a Buffer * argument to MathData constructor
In order to ensure that MathData objects have a valid buffer, the
default MathData() constructor is deleted. This means that a buffer
shall be specified for each MathData object created.

This is fairly mechanical, actually. In particular, in most
InsetMathXxx cases, in MathData and in MathParser, the available
buffer_ member is used.

More specific cases:
- lyxfind.cpp takes the buffer from the Cursor

- calls to vector<MathData>::resize take an additional
  MathData(buffer_) parameter. There are cases where resize actually
  remove cells, and in this case clear() or even erase() have been
  used.

- in InsetMathMacroTemplate, the optional parameters of the
  constructors cannot be allowed anymore (a default value cannot
  depend on another parameter). Therefore there a now two constructors
  instead.

- in MathAutoCorrect.cpp, the MathData objects are not bound to a
  buffer, so that std::nullptr is used instead.

- in MathExtern, use a buffer when one is specified, std::nulptr
  instead.

(cherry picked from commit 57d7130655)
2024-07-05 12:21:47 +02:00
Enrico Forestieri
4acc6e36e3 Fix textstyle-update handling in mathed
The code was expecting that all properties were specified
in the argument and not only some. Simply do not process
those properties not specified in the argument.

(cherry picked from commit afb70c905b)
2024-06-09 13:10:15 -04:00
Richard Kimberly Heck
701c763221 Merge branch '2.4.x' into 2.4.1-devel 2024-06-02 21:49:54 -04:00
Jean-Marc Lasgouttes
2699a58cd7 Set buffer when creating a MathData from parts of another one
This is triggered by selecting part of an equation under Xcb platform
(x11). Indeed, the current selection has to be sent to the X11 server
and BufferView::requestSelection() is called. Eventually
cap::grabSelection() is the function that creates this partial
MathData object.

Fixes ticket #12947.

(cherry picked from commit ed2f3cb9cf)
2024-06-01 18:45:43 +02:00
Jean-Marc Lasgouttes
76188dcdf1 Try to make sure that math insets have a properly set buffer_ member
Set the buffer of contents that is added to a MathData object through
MathData::insert() (both versions)
MathData::push_back()
asArray()

Also in math macros, initialize look_ with the relevant buffer.

This reduces the number of insets hat do not have a proper buffer.

See #13050 for discussion of this issue.

(cherry picked from commit f3c5ff9cb7)
2024-06-01 18:45:43 +02:00
Jean-Marc Lasgouttes
13a34d6cd1 Set buffer_ correctly when inseting a math macro over a selection
The code that handles this special macro insertion (in
Cursor::mathMacroClose())) is very weird: it inserts the contents of
the macro _after_ the macro and later, since the macro is 'greedy', it
will eat this contents and put it in its first macro cell.

Does it make sense to you? It does not ake sense to me either. Anyway,
this is the point where one should make sure that the buffer is set.

Fixes ticket #12682.

(cherry picked from commit b45a957929)
2024-04-25 20:27:36 +02:00
Juergen Spitzmueller
1dad179256 Fix label escaping in InsetMathRef (#12980)
This was completely broken: the IDs have been escaped in the LyX file
(which they absolutely shouldn't) but not in all LaTeX output (which
they should).

(cherry picked from commit 98080ca0d5)
2024-04-02 20:20:13 +02:00
Juergen Spitzmueller
31ec96e01f Fix context menu of InsetMathRef 2024-04-01 17:59:56 +02:00
Jean-Marc Lasgouttes
4dfebbe9da Fix display of a math hull inset in a tight inset
This is a kind of hack. This allows InsetMathHull to state that it
needs some elbow room beyond its width, in order to fit the numbering
and/or the left margin (with left alignment), which are outside of the
inset itself.

To this end, InsetMathHull::metrics() sets a value in
MetricsInfo::extrawidth and this value is added later to the width of
the row that contains the inset (when this row is tight or shorter
than the max allowed width).

Fixes bug #12320.
2024-03-22 15:40:40 +01:00
Jean-Marc Lasgouttes
6d62d8009f Revert "Fix display of a math hull inset in a tight inset"
This commit will be replaed by a better solution.

Part of ticket #12320.

This reverts commit 4bbd4a45e7.
2024-03-22 15:08:26 +01:00
Thibaut Cuvelier
fd37845075 Amend 16660d12.
The previous commit introduced wrong behaviours for <>. The new code carefully escapes what needs to be escaped from LaTeX, using the now-standard XML tools (XMLStream).
2024-03-21 21:32:45 +01:00
Thibaut Cuvelier
16660d12b4 MathML in HTML: don't escape <> for a raw LaTeX output.
In some cases (I only found numbered equations), the LaTeX output still has a bit of HTML. For numbered equations, using \tag{X} (as suggested in https://www.lyx.org/trac/ticket/13048) would require fiddling with the output. KaTeX doesn't support \label. This patch is probably the easiest and most reliable fix.

Fixes https://www.lyx.org/trac/ticket/13048.
2024-03-21 00:29:23 +01:00
Thibaut Cuvelier
7e6597a5b4 MathML: don't let the processor stretch operators when they are single characters for LyX.
The main goal is to match TeX' behaviour. If you want stretchy operators, use InsetMathDelim / \left & \right. This patch will change the output in many files, but making the rendering much closer to that of TeX (which users should expect, due to LyX' roots in TeX).
2024-03-11 02:00:47 +01:00
Thibaut Cuvelier
8f820d7ccb MathML: stop stretching all delimiters.
No form? Reference: https://w3c.github.io/mathml-core/#dfn-form. The MathML processor is smart enough to determine whether the delimiter is prefix or postfix.

No stretchy/symmetric/fence in all cases? Reference: https://w3c.github.io/mathml-core/#algorithm-for-determining-the-properties-of-an-embellished-operator and https://w3c.github.io/mathml-core/#operator-dictionary-human (example entry: U+0028). Delimiters have the right properties by default.
2024-03-11 01:40:16 +01:00
Thibaut Cuvelier
be03d69946 MathML: don't output delimiters in InsetMathBinom and
InsetMathDelim if the delimiter is a space.
2024-03-11 01:30:48 +01:00
Thibaut Cuvelier
9e6b810b37 Extract vert, langle, rangle in MathExtern like parentheses and brackets.
This patch is part of a series that aims at solving https://www.lyx.org/trac/ticket/12891. It is an excerpt of the patch that lynx published at https://www.lyx.org/trac/ticket/12270.
2024-03-11 01:22:12 +01:00
Thibaut Cuvelier
b1a4eb118c Improve const correctness. 2024-03-11 01:15:53 +01:00
Thibaut Cuvelier
93444892c5 Memorise whether delims are extracted from MathExtern.
This patch is part of a series that aims at solving https://www.lyx.org/trac/ticket/12891. It should not change any output.
2024-03-11 01:10:15 +01:00
Thibaut Cuvelier
1680eaf5f0 Reduce code duplication. 2024-03-10 16:58:45 +01:00
Thibaut Cuvelier
011c3d73c0 MathML: consider ordinary and alphabetical characters as identifiers instead of operators.
The goal is to consider all Greek letters as identifiers instead of operators.

Solves: https://www.lyx.org/trac/ticket/12948.
2024-03-09 20:59:12 +01:00
Thibaut Cuvelier
1b11dfeca5 Simplify a loop with a for-each.
These loops were brought by C++11. The next step could be using std::any_of.
2024-03-09 20:46:54 +01:00
Jean-Marc Lasgouttes
765c380a5b Pass strings as reference
Spotted by coverity.
2024-01-12 14:34:45 +01:00
Udi-Fogiel
9ebc7d9512 Amend 7441172d
colswitch was checking for oldstyle instead of normalcolor
to see if we need \normalcolor, which lead to appearence
of \color{none} in some cases, but "none" is not a known
color.
2023-12-29 20:10:50 +01:00
Jean-Marc Lasgouttes
94118b865e Disable properly math inset locking
It is not clear whether this feature was once documented and used (it
would have been 20 years ago).

It is mostly disable now, but there was a remaining bit that is
annoying now.

I'll try to restore this later.
2023-12-08 15:32:21 +01:00
Jean-Marc Lasgouttes
a635e461a1 Remove code that has been dead for almost 20 years 2023-11-30 10:07:44 +01:00
Enrico Forestieri
ee19d67524 Amend 58103cf2
- Do not clear the initial selection to allow consecutive changes
  (this is in line with the behavior in texted)
- Make the color changes last so that the underline is the right color
- Allow to operate on selections that span multiple cells in a grid
- Use \boldsymbol instead of \mathbf to make everything bold
2023-11-17 19:03:46 +01:00
Enrico Forestieri
039de52ad9 Amend 58103cf2
The \underbar macro is a text mode macro that can also be used
in math mode. However, when inserting it in mathed, LyX helpfully
wraps it in a \text inset. One can dissolve such text inset and
the macro would appear in math mode without any problem. But the
output routine thinks that the user is shooting itself in the
foot and tries to protect him by wrapping \underbar in the
\lyxmathsym macro, whose definition is normally added to the
preamble when an unicode character is used in math mode.

Of course, this is not the case for \underbar and a compile
error arises. The easier solution is to simply add lyxmathsym as
a requirement for \underbar in lib/symbols, but this means
that the definition of \lyxmathsym would be added even when not
necessary (because in the validation routine we miss the info
about the current mode). The correct solution is acknowledging
the dual nature of \underbar as a text-mode macro that can also
be used in math mode. Luckily the correct solution is almost as
easy as the easier one and is what is done in this commit.
2023-11-09 00:21:21 +01:00
Enrico Forestieri
bdaad03a45 Do not accumulate underline changes
If an element is underlined in mathed by using the text properties
dialog, the changes accumulate. So, for example, to change a single
underline to a double one, one would need removing the previous
underline first. This commit allows using the text properties
dialog and simply replace an underline type with another one.

However, this works only if the underlined element is not included
in some other inset. For example, given "\uline{\text{abc}}",
selecting the 'b' and choosing a double underline produces
"\uline{\text{a\uuline{b}c}}". But, given "\text{\uline{abc}}", and
operating as before produces "\text{\uline{a}\uuline{b}\uline{c}}".
2023-11-08 09:17:38 +01:00
Enrico Forestieri
ea30f1feb1 Amend 58103cf2
Give a variable a more meaningful name and fix a typo.
2023-11-08 08:56:40 +01:00
Enrico Forestieri
f8f2355445 Silence compiler warning 2023-11-06 21:03:23 +01:00
Enrico Forestieri
9d95147528 Amend 58103cf2
Correct file name.
2023-11-06 18:46:22 +01:00
Enrico Forestieri
58103cf214 Allow using the text properties dialog in mathed
Until now only the color of the text could be changed by using
the text properties dialog. This commit allows changing all
other properties except for strikethrough. It is possible to
also add underlining with the limitation that the changes
accumulate. This requires other work but I think that underlining
and strikethrough are not so important in mathed and can be
refined at a later time.

Fixes #12958
2023-11-06 18:04:44 +01:00
Enrico Forestieri
75a08df529 Inherit outer font in text-in-math environments
Some text-in-math environments such as \text, \mbox, \fbox, and
\makebox, inherit the outer text font. This commit reflects this
in the on-screen representation.

Fixes #12950.
2023-11-02 17:54:02 +01:00
Enrico Forestieri
e0e1350b7e Revert "Inherit outer font in text-in-math environments"
This reverts commit d72b9b0238.

Unfortunately, the font taken into account is the font at the
current cursor position rather than the font of the corresponding
math inset.
2023-11-02 01:59:54 +01:00
Enrico Forestieri
d72b9b0238 Inherit outer font in text-in-math environments
The text-in-math environments such as \text, \mbox, \fbox, \makebox
and so on, inherit the outer text font. This commit reflects this
in the on-screen representation.

Fixes #12950.
2023-11-01 22:21:49 +01:00
Pavel Sanda
28f81d1be5 Revert "MathML: don't output delimiters in InsetMathBinom and InsetMathDelim if the delimiter is a space."
This reverts commit be44cb8516, see #12891.
2023-10-27 21:18:45 +02:00
Jean-Marc Lasgouttes
99ecdd6ceb Fixup 65cb9fa4: avoid extra spacing when selecting math
This was happening whenever a selection started/ended after a fraction
inset.
2023-10-18 12:30:55 +02:00
Jean-Marc Lasgouttes
ff7696f184 Do not use Color_selectionmath when selection is gone
It might happen that the selection goes away without recomputing
metrics (for example with char-forward). The added test is a bit of a
band-aid for this situation. A better solution would be to understand
better when metrics computation is triggered in mathed.
2023-10-12 11:30:47 +02:00
Jean-Marc Lasgouttes
174dc2c8be Use Color_selectionmath as needed for multi-cell selection in math
This is complementary to partial selection implemented at 65cb9fa4.
2023-10-12 11:30:47 +02:00
Thibaut Cuvelier
be44cb8516 MathML: don't output delimiters in InsetMathBinom and InsetMathDelim if the delimiter is a space. 2023-10-11 20:37:38 +02:00
Juergen Spitzmueller
5cb53606b6 Introduce color_selectionmath
To have a distinctive color for selected math which works in both modes

Also, link color_selectionmath with QPalette::HighlightedText, so we
won't need to special-case on lyxrc.use_system_colors any longer
2023-10-04 13:10:07 +02:00
Jean-Marc Lasgouttes
65cb9fa4df Use Color_selectiontext as needed for partial selection in math
Currently, selected math hull insets use Color_selectiontext when
system colors are in use. This commit implements the same behavior
for partial selection.

This is done by introducing two element types (BEGIN_SEL and END_SEL)
to MathRow.
2023-10-03 12:51:11 +02:00
Jean-Marc Lasgouttes
9156712895 Make sure that caret width is not null in mathed
The same test exists in texted.

Fixes bug #12904.
2023-09-24 13:07:55 +02:00
Jean-Marc Lasgouttes
94c6d45b74 When drawing macro names, enforce LtR direction
Add a Direction parameter to the Painter::text methods that take a
FontInfo parameter.

In drawStrRed and drawStrBlack, force the direction to LtR.

Fixes bug #12905.
2023-09-22 12:41:44 +02:00