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

Change align environment cell alignment order #64

Open
wants to merge 4 commits into
base: align-fix-cursor-in-top-row
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 1 addition & 44 deletions src/commands/math/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -945,9 +945,6 @@ Environments.matrix = P(Environment, function(_, super_) {
trs += '<tr>$tds</tr>';
cells[row] = [];
}
if (this.parent.htmlColumnSeparator && !isFirstColumn) {
cells[row].push(this.parent.htmlColumnSeparator);
}
cells[row].push('<td>&'+(i++)+'</td>');
});

Expand Down Expand Up @@ -1204,9 +1201,6 @@ Environments.matrix = P(Environment, function(_, super_) {
block = MatrixCell(row+1);
block.parent = this;
newCells.push(block);
if (this.htmlColumnSeparator && !isFirstColumn) {
newRow.append($(this.htmlColumnSeparator));
}
isFirstColumn = false;
// Create cell <td>s and add to new row
block.jQ = $('<td class="mq-empty">')
Expand Down Expand Up @@ -1323,50 +1317,13 @@ Environments.Vmatrix = P(Matrix, function(_, super_) {
// differently in latex. Nevertheless, we want it to render as a table so it's convenient to extend Matrix.
Environments['align*'] = P(Matrix, function (_, super_) {
_.environment = 'align*';
_.extraTableClasses = 'mq-rcl';
_.extraTableClasses = 'mq-align';
_.createBlocks = function() {
this.blocks = [
MatrixCell(0, this),
MatrixCell(0, this),
];
}
_.htmlColumnSeparator = '<td class="mq-align-equal">=</td>';
_.delimiters = {
column: '&=',
row: '\\\\',
};

// Don't delete empty columns, the align environment is for equations and should always have two columns.
_.removeEmptyColumns = false;

// For the same reason, don't allow adding columns.
_.addColumn = function() {};

// jQadd hack to keep the cursor in the correct row on seek
_.jQadd = function(jQ) {
var cmd = this, eachChild = this.eachChild;
jQ = super_.jQadd.call(this, jQ);

// Listen for mousedown on td.mq-align-equal descendants
// Handler will run just before `this.seek` is triggered by a similar
// listener in the controller.
jQ.delegate('td.mq-align-equal', 'mousedown.mathquill.alignenv', function (e) {
var tds = $(e.currentTarget).siblings('td');
var row = Fragment(
Node.byId[tds[0].getAttribute(mqBlockId)],
Node.byId[tds[1].getAttribute(mqBlockId)]
);

// Temporarily monkey-patch eachChild so that seek is limited
// to this row only.
// TODO - fix this properly
cmd.eachChild = function() {
row.each.apply(row, arguments);
cmd.eachChild = eachChild;
};
});
return jQ;
};
});

// Replacement for mathblocks inside matrix cells
Expand Down
9 changes: 3 additions & 6 deletions src/css/math.less
Original file line number Diff line number Diff line change
Expand Up @@ -389,14 +389,11 @@
margin-bottom: 1px;
}

&.mq-rcl {
td:nth-child(1) {
&.mq-align {
td:nth-child(odd) {
text-align: right;
}
td:nth-child(2) {
text-align: center;
}
td:nth-child(3) {
td:nth-child(even) {
text-align: left;
}
}
Expand Down
34 changes: 24 additions & 10 deletions test/visual.html
Original file line number Diff line number Diff line change
Expand Up @@ -290,21 +290,35 @@ <h3>Text mode</h3>
<p>Mutiple consecutive spaces in the middle of a text mode block should not collapse into one space: <span class="mathquill-static-math">\text{three spaces}</span></p>

<h3>Matrix align* environments</h3>
<p>align* environments should render with each row's = sign aligned, the LHS aligned right, and the RHS aligned left
<p>align* environments should render in a similar manner to matrix environments, except their cell alignment occurs in the order {rlrlrlrl...}</p>
<span class="mathquill-static-math">
\begin{align*}
\frac{3x + y}{7} &amp;&amp;= 9 &amp;&amp; \text{given} \\
3x + y &amp;&amp;= 63 &amp;&amp; \text{multiply by 7} \\
3x &amp;&amp;= 63 - y &amp;&amp; \text{subtract y} \\
x &amp;&amp;= 21 - \frac{y}{3} &amp;&amp; \text{divide by 3} \\
\end{align*}
</span>
<p>They can align on any symbol prefixed by an &amp;</p>
<span class="mathquill-static-math">
\begin{align*}
f(x) &amp;= x^4 + 7x^3 + 2x^2 \\
&amp;+ 10x + 12
\end{align*}
</span>
<p>They may also have multiple equations per line</p>
<span class="mathquill-static-math">
\begin{align*}
y &amp;= mx+c \\
y-c &amp;= mx \\
\frac{y-c}{m} &amp;= x
\end{align*}
f(x) &amp;= a x^2+b x +c &amp; g(x) &amp;= d x^3 \\
f'(x) &amp;= 2 a x +b &amp; g'(x) &amp;= 3 d x^2
\end{align*}
</span>
</p>align* environments can be edited. New row: shift+enter.<p>
<span class="mathquill-math-field">
\begin{align*}
y &amp;= mx+c \\
y-c &amp;= mx \\
\frac{y-c}{m} &amp;= x
\end{align*}
\begin{align*}
f(x) &amp;= (x+a)(x+b) \\
&amp;= x^2 + (a+b)x + ab
\end{align*}
</span>
</p>

Expand Down