Add an 'implicit group' parser, use with sizing

Summary:
Implicit groups are objects that act like groups but don't have brackets around
them. This is used for things like sizing functions or font-change functions
that can occur in the middle of the group, but act like they apply to a group
after them which stops when the current group stops. E.g. `Hello {world \Large
hello} world` produces normal, normal, Large, normal text. (Note, I just came up
with the name implicit group, I don't think this is actually how it is parsed in
LaTeX but it fits nicely with the current parsing scheme and seems to work
well).

For now, apply this to the sizing functions (we don't have any other functions
that act like this). Also note that this doesn't really do much practically
because we limit sizing functions to only be on the top level of the expression,
but it does let people do `\Large x` and get a large `x`, without having to add
braces.

Test Plan:
 - Run the tests, see they work
 - Make sure `abc \Large abc` looks correct

Reviewers: alpert

Reviewed By: alpert

Differential Revision: http://phabricator.khanacademy.org/D10876
This commit is contained in:
Emily Eisenberg
2014-07-10 16:06:19 -07:00
parent e46dd418b3
commit 02935f7dde
5 changed files with 118 additions and 43 deletions

View File

@@ -310,14 +310,36 @@ big parens
.sizing { display: inline-block; }
.reset-size5.size1 { font-size: 0.5em; }
.reset-size5.size2 { font-size: 0.7em; }
.reset-size5.size3 { font-size: 0.8em; }
.reset-size5.size4 { font-size: 0.9em; }
.reset-size5.size5 { font-size: 1.0em; }
.reset-size5.size6 { font-size: 1.2em; }
.reset-size5.size7 { font-size: 1.44em; }
.reset-size5.size8 { font-size: 1.73em; }
.reset-size5.size9 { font-size: 2.07em; }
.reset-size5.size10 { font-size: 2.49em; }
@size-1: 0.5;
@size-2: 0.7;
@size-3: 0.8;
@size-4: 0.9;
@size-5: 1.0;
@size-6: 1.2;
@size-7: 1.44;
@size-8: 1.73;
@size-9: 2.07;
@size-10: 2.49;
.generate-size-change(@from, @to) {
.reset-size@{from}.size@{to} {
@sizeFromVariable: ~"size-@{from}";
@sizeToVariable: ~"size-@{to}";
font-size: (@@sizeToVariable / @@sizeFromVariable) * 1em;
}
}
.generate-to-size-change(@from, @currTo) when (@currTo =< 10) {
.generate-size-change(@from, @currTo);
.generate-to-size-change(@from, (@currTo + 1));
}
.generate-from-size-change(@currFrom) when (@currFrom =< 10) {
.generate-to-size-change(@currFrom, 1);
.generate-from-size-change((@currFrom + 1));
}
.generate-from-size-change(1);
}