Skip to content

Add '$$' at the beginning and end of empty latex equations to have them render correctly - #8213

Merged
David Kutugata (DavidKutu) merged 5 commits into
masterfrom
davidkutu/latex_equations
Oct 28, 2019
Merged

David Kutugata (DavidKutu) merged 5 commits into
masterfrom
davidkutu/latex_equations

Conversation

@DavidKutu

Copy link
Copy Markdown

For #7992

  • Pull request represents a single change (i.e. not fixing disparate/unrelated things in a single PR)
  • Title summarizes what is changing
  • Has a news entry file (remember to thank yourself!)
  • Appropriate comments and documentation strings in the code
  • Has sufficient logging.
  • Has telemetry for enhancements.
  • Unit tests & system/integration tests are added/updated
  • Test plan is updated as appropriate
  • package-lock.json has been regenerated by running npm install (if dependencies have changed)
  • The wiki is updated with any design decisions/details.

 equations to have them render correctly.
@codecov-io

Codecov (codecov-io) commented Oct 25, 2019 •

Copy link
Copy Markdown

Codecov Report

Merging #8213 into master will decrease coverage by 0.06%.
The diff coverage is 93.75%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8213      +/-   ##
==========================================
- Coverage   58.79%   58.73%   -0.07%     
==========================================
  Files         504      505       +1     
  Lines       23090    23109      +19     
  Branches     3723     3731       +8     
==========================================
- Hits        13576    13572       -4     
- Misses       8645     8656      +11     
- Partials      869      881      +12
Impacted Files Coverage Δ
...science-ui/interactive-common/latexManipulation.ts 93.75% <93.75%> (ø)
src/client/testing/serviceRegistry.ts 48.64% <0%> (-46.85%) ⬇️
src/client/testing/codeLenses/main.ts 44.44% <0%> (-33.34%) ⬇️
...t/datascience/jupyter/jupyterDataRateLimitError.ts 66.66% <0%> (-33.34%) ⬇️
src/client/formatters/serviceRegistry.ts 75% <0%> (-25%) ⬇️
...ience/jupyter/jupyterDebuggerRemoteNotSupported.ts 75% <0%> (-25%) ⬇️
...cience/jupyter/jupyterDebuggerNotInstalledError.ts 60% <0%> (-20%) ⬇️
src/client/common/utils/icons.ts 83.33% <0%> (-16.67%) ⬇️
src/client/api.ts 78.57% <0%> (-14.29%) ⬇️
src/client/datascience/cellFactory.ts 75.86% <0%> (-13.8%) ⬇️
... and 16 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8b4d879...2d4380d. Read the comment docs.

Comment thread src/datascience-ui/interactive-common/cellOutput.tsx Outdated
return input;
}

private getAllIndexesOf(arr: string, value: string): number[] {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

getAllIndexesOf [](start = 12, length = 15)

I think you could likely do this with regexs?
const beginReg = /\begin/g;
const endReg = /\end/g;
while (result = beginReg.exec(input)) {
result.index is index of match
beginReg.lastIndex is next match

@IanMatthewHuff Ian Huff (IanMatthewHuff) Oct 25, 2019 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Did you take a look at how Jupyter does this? The equation matching looks more complex to me.
https://github.com/jupyter/notebook/blob/ff29ba8ab006e59bc264e0ea33084755533535c8/docs/source/examples/Notebook/Typesetting%20Equations.ipynb


In reply to: 339142495 [](ancestors = 339142495)

@IanMatthewHuff Ian Huff (IanMatthewHuff) Oct 25, 2019 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Here is what you want.
https://github.com/jupyter/notebook/blob/d60445e92666a0c5651a33e180c92051d94a7d44/notebook/static/notebook/js/mathjaxutils.js

Looks like we might need to check licensing as well.


In reply to: 339245020 [](ancestors = 339245020,339142495)

@IanMatthewHuff Ian Huff (IanMatthewHuff) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🕐

David Kutugata added 2 commits October 25, 2019 15:09
Started using Regular Expressions instead of indexOf
Added unit tests
const beginIndexes = getAllIndexesOfRegex(input, /\\begin/g);
const endIndexes = getAllIndexesOfRegex(input, /\\end/g);

for (let i = 0; i < beginIndexes.length; i += 1) {

@IanMatthewHuff Ian Huff (IanMatthewHuff) Oct 25, 2019 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this would have issues with mismatched begin / end pairs. The code is assuming that an equal number of \begin and \end matches were found, but you could have valid markdown with just those strings in it.
I think it's worth taking a look at this regex that I linked to see if it breaks out latex bits from a markdown block.

it now includes the opening anc closing brackets,
with whatever name the user chooses.

Also, the code will run only if the amount of indexes are the same.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Adds '$$' to latex formulas that don't have a '$', allowing users to input the formula directly.
function fixLatexEquations(input: string): string {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
function fixLatexEquations(input: string): string {
export function fixLatexEquations(input: string): string {

return indexes;
}

export { fixLatexEquations };

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is not required in typescript.

@rchiodo Rich Chiodo (rchiodo) left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

:shipit:

@IanMatthewHuff Ian Huff (IanMatthewHuff) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

:shipit:

@DavidKutu
David Kutugata (DavidKutu) merged commit 306f5dc into master Oct 28, 2019
@DavidKutu
David Kutugata (DavidKutu) deleted the davidkutu/latex_equations branch October 28, 2019 23:27
@lock lock Bot locked as resolved and limited conversation to collaborators Nov 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants