Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix LaTeX output of FreeModuleTensor.display_comp #37823

Merged
merged 1 commit into from
May 2, 2024

Conversation

egourgoulhon
Copy link
Member

@egourgoulhon egourgoulhon commented Apr 17, 2024

📝 Checklist

  • The title is concise and informative.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation and checked the documentation preview.

⌛ Dependencies

None.

This PR fixes an issue of the method display_comp of class FreeModuleTensor, which arises when the LaTeX name of a tensor contains the symbol ^ or _. For instance, in Sage 10.4.beta3, we have:

sage: E.<x,y> = EuclideanSpace()
sage: g = E.metric()
sage: latex(g.inverse().display_comp())
\begin{array}{lcl} g^{-1}_{\phantom{\, x}\phantom{\, x}}^{ \, x \, x } & = & 1 \\ 
g^{-1}_{\phantom{\, y}\phantom{\, y}}^{ \, y \, y } & = & 1 \end{array}

This is incorrect LaTeX syntax: the symbol g gets two exponent markers (^). Consequently, in a Jupyter notebook in %display latex mode, the command g.inverse().display_comp() will not generate any typeset output.

This is fixed here by making the LaTeX output of display_comp more robust: the LaTeX symbol of the tensor (g^{-1} in the above example) is now enclosed between two braces (e.g. g^{-1} is changed into {g^{-1}}) before adding indices to it.

Copy link

Documentation preview for this PR (built with commit 6874f7d; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

Copy link
Contributor

@mkoeppe mkoeppe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, a simple and clean fix.

@egourgoulhon
Copy link
Member Author

Thank you for the review!

vbraun pushed a commit to vbraun/sage that referenced this pull request Apr 28, 2024
    
<!-- ^ Please provide a concise and informative title. -->
<!-- ^ Don't put issue numbers in the title, do this in the PR
description below. -->
<!-- ^ For example, instead of "Fixes sagemath#12345" use "Introduce new method
to calculate 1 + 2". -->
<!-- v Describe your changes below in detail. -->
<!-- v Why is this change required? What problem does it solve? -->
<!-- v If this PR resolves an open issue, please link to it here. For
example, "Fixes sagemath#12345". -->



### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [ ] I have linked a relevant issue or discussion.
- [x] I have created tests covering the changes.
- [x] I have updated the documentation and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->

None.

This PR fixes an issue of the method `display_comp` of class
`FreeModuleTensor`, which arises when the LaTeX name of a tensor
contains the symbol `^` or `_`. For instance, in Sage 10.4.beta3, we
have:

```
sage: E.<x,y> = EuclideanSpace()
sage: g = E.metric()
sage: latex(g.inverse().display_comp())
\begin{array}{lcl} g^{-1}_{\phantom{\, x}\phantom{\, x}}^{ \, x \, x } &
= & 1 \\
g^{-1}_{\phantom{\, y}\phantom{\, y}}^{ \, y \, y } & = & 1 \end{array}
```
This is incorrect LaTeX syntax: the symbol  `g` gets two exponent
markers  (`^`). Consequently, in a Jupyter notebook in  `%display latex`
mode, the command `g.inverse().display_comp()` will not generate any
typeset output.

This is fixed here by making the LaTeX output of `display_comp` more
robust: the LaTeX symbol of the tensor (`g^{-1}` in the above example)
is now enclosed between two braces (e.g. `g^{-1}` is changed into
`{g^{-1}}`) before adding indices to it.
    
URL: sagemath#37823
Reported by: Eric Gourgoulhon
Reviewer(s): Matthias Köppe
@vbraun vbraun merged commit 3041aac into sagemath:develop May 2, 2024
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants