-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feat(array): add support for repetition in format description #3583
base: main
Are you sure you want to change the base?
Conversation
Can someone explain why the test for flow is breaking ? The logs seem to say that
It seems to ignore that source location has other properties :
|
Because Instead of reading the text directly from the lexer, I think it would be better to iterate over the contents of the node and extract the |
I have made the changes and and my commit is awaiting approval before it will be tested. |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #3583 +/- ##
==========================================
+ Coverage 92.99% 93.49% +0.49%
==========================================
Files 91 89 -2
Lines 6779 6637 -142
Branches 1576 1541 -35
==========================================
- Hits 6304 6205 -99
+ Misses 437 401 -36
+ Partials 38 31 -7
... and 19 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
|
Hello, I have added a test for this feature so that codecov is also happy. |
Hello, I have fixed all the things I could figure out how to fix. The deploy checks for netlify are currently failing, but as far as I can tell, its not because of and of my changes ? |
Hello, |
bump |
@edemaine does this PR require any more work from me to get merged? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry this took so long to review. The main comment here is we should support *
anywhere in the colalign
string, not just at the beginning.
@@ -1260,6 +1260,10 @@ describe("A begin/end parser", function() { | |||
expect`\begin{array}{cc}a&b\\c&d\end{array}`.toParse(); | |||
}); | |||
|
|||
it("should parse an environment with argument in repetition format", function() { | |||
expect`\begin{array}{*{35}{l}} x+y\le 12, \ 2x-y\ge 0, \ x-2y\le 0\end{array}`.toParse(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a toParseLike
test would be more helpful here. E.g. \begin{array}{*{10}{l}}...
should parse like \begin{array}{llllllllll}...
.
@@ -786,7 +786,31 @@ defineEnvironment({ | |||
const symNode = checkSymbolNodeType(args[0]); | |||
const colalign: AnyParseNode[] = | |||
symNode ? [args[0]] : assertNodeType(args[0], "ordgroup").body; | |||
const cols = colalign.map(function(nde) { | |||
let myColAlign = []; | |||
if (colalign[0].text === "*") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to only support *
at the beginning of colalign
. But *
can be used anywhere, e.g. \begin{array}{ll*{5}{lcr}rr*5{rrcl}}
. I think ideally you'd do a map
to expand all instances of *
.
const cols = colalign.map(function(nde) { | ||
let myColAlign = []; | ||
if (colalign[0].text === "*") { | ||
const repeatCol = assertNodeType(colalign[1], "ordgroup"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to only support *{123}
with braces. But for single-character numbers, you can omit the braces. For example, *5
should work.
const iRepeat = assertNodeType(repeatCol.body[i], "textord"); | ||
repeatString += iRepeat.text ; | ||
} | ||
const nRepeat = parseInt(repeatString); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should use Number
(or parseInt(..., 10)
) to force decimal parsing.
I see that there's similar code (which uses Number
) when computing numMaths
. Could this be factored out into a helper function? (with the comment above too) Converting text to numbers like this is quite useful... In fact, I see a totally different implementation of it (which I maybe wrote?) in macros.js
under defineMacro("\\char"
. 😮
It is now possible to describe an array environment like
\begin{array}{* {35}{l}}
This completes task number 3 on
#269
What is the previous behavior before this PR?
When encountering an array environment described with the repetition format (
\begin{array}{* {7}{cl}
), KaTeX would throw an error and not render the equation.What is the new behavior after this PR?
Equation now renders as expected.
Contribtues to #269