-
-
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
Support \hline #1306
Support \hline #1306
Conversation
Fixes issue #1271
Support `\hline`.
Codecov Report
@@ Coverage Diff @@
## master #1306 +/- ##
==========================================
- Coverage 84.24% 83.92% -0.32%
==========================================
Files 61 61
Lines 3973 4001 +28
Branches 662 665 +3
==========================================
+ Hits 3347 3358 +11
- Misses 532 546 +14
- Partials 94 97 +3
Continue to review full report at Codecov.
|
The commit |
@ylemkimon I don't think it's actually a problem. @ronkok's last few PRs have been this way, and the old commits get swept up in the squash. At some point it'd be good to start new PRs from the master branch, though. (For me it's |
@ronkok Wow, it's exciting to see how this is relatively easy thanks to stretchy There are two natural features that aren't yet in this PR; is it worth adding them now?
|
@ylemkimon GitH(Hub) has been acting that way since I did manual edit on a merge conflict in the |
@edemaine Later today, I'll add the double No promises on |
src/environments/array.js
Outdated
possibleHLine = parser.nextToken.text; | ||
} | ||
if (possibleHLine === "\\hline") { | ||
hlines.push(true); |
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.
Can group.value.addHLines = true;
be done here?
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.
@ylemkimon Stand by. I've got a code cleanup commit coming in about an hour. It will change this section of the code.
src/environments/array.js
Outdated
while (/\s/.test(possibleHLine)) { | ||
parser.consume(); | ||
possibleHLine = parser.nextToken.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.
Could this be done by parser.consumeSpaces()
? (same for above)
Now I think this is ready for review. I will also need some help to create screenshots for Hline. |
The screenshot renders as 1246x752, but needs to be at most 1024x768. Can you make it a little less wide, e.g., reducing the |
There's no point in cutting it close. One of the arrays was redundant and I took it out. |
src/environments/array.js
Outdated
while (/^\s$/.test(next)) { | ||
parser.consume(); | ||
next = parser.nextToken.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.
Could this be done using parser.consumeSpaces()
?
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.
Yes. Please use that instead.
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.
Will do.
src/environments/array.js
Outdated
if (nextTokenIsHLine(parser)) { | ||
numHLinesBeforeRow[0] = 2; | ||
} | ||
} else { |
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 the following is more readable (same for below), but it's matter of personal preference:
if (nextTokenIsHLine(parser)) {
if (nextTokenIsHLine(parser)) {
numHLinesBeforeRow.push(2);
} else {
numHLinesBeforeRow.push(1);
}
} else {
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.
Is there something magic about 2? Why not a while
loop and counter? Does LaTeX not support more than 2 \hline
s?
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.
Until just now, I had never tried more than two \hline
s. while
loop coming right up.
src/environments/array.js
Outdated
for (let i = 2; i <= numHLinesBeforeRow[0]; i++) { | ||
totalHeight += 0.25; | ||
hlinePos.push(totalHeight); | ||
} |
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 can be simplified to (same for below):
if (numHLinesBeforeRow[0] > 0) {
totalHeight += 0.25 * (numHLinesBeforeRow[0] - 1);
hlinePos.push(totalHeight);
}
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.
@ylemkimon We need a loop in order to handle multiple \hline
s. So I think you mean that the code could read something like:
for (let i = 1; i <= numHLinesBeforeRow[0]; i++) {
if (i > 1) {
totalHeight += 0.25;
}
hlinePos.push(totalHeight);
}
That would be simpler for a human to read. But force of habit makes me try to avoid putting conditional statements inside a loop. Maybe this is not the place for that kind of thing. After all, we're not likely to get very many \hline
s.
Would you prefer my suggested revision to the current code?
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.
@ronkok I thought hlinePos
is added only once, sorry. I think we can leave as-is.
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 thought
hlinePos
is added only once
Which goes to show that code I suggested above would indeed be easier for a human to read. The speed loss with so few \hline
s is negligible. I'll make the change.
src/environments/array.js
Outdated
return true; | ||
} | ||
return false; | ||
} |
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.
How about:
function getNumHLines(parser: Parser): number {
let n = 0;
parser.consumeSpaces();
while (parser.nextToken.text === "\\hline") {
parser.consume();
n++;
parser.consumeSpaces();
}
return n;
}
(or for
loop if you prefer) and
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 like it.
src/environments/array.js
Outdated
// Test for \hline at the top of the array. | ||
while (nextTokenIsHLine(parser)) { | ||
numHLinesBeforeRow[0] += 1; | ||
} |
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.
const numHLinesBeforeRow = [];
numHLinesBeforeRow.push(getNumHLines(parser));
(same for below)?
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.
That's an outstanding suggestion. I'll do it.
Once again, I'll need help to generate a screenshot for HLine. Sorry to be a burden. |
Thanks, @edemaine! |
Support
\hline
. Fix #267, part of #269.