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

Support for expandable environment names #1024

Merged
merged 1 commit into from Jul 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/LaTeXML/Package/LaTeX.pool.ltxml
Expand Up @@ -140,9 +140,9 @@ Let('\@currenvline', '\@empty');

DefMacro('\begin{}', sub {
my ($gullet, $env) = @_;
my $name = $env && ToString($env);
my $before = LookupValue('@environment@' . ToString($_[1]) . '@beforebegin');
my $after = LookupValue('@environment@' . ToString($_[1]) . '@atbegin');
my $name = $env && ToString(Expand($env));
Copy link
Collaborator

@dginev dginev Jul 27, 2018

Choose a reason for hiding this comment

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

question: Shouldn't this be realized via the parameter type? E.g. replacing the \begin{} via an \begin XToken or such? cc @brucemiller

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, if $name is undefined / empty we probably want to throw an error

Copy link
Owner

Choose a reason for hiding this comment

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

Well, yeah, sorta, but ... No. There's an Expanded parameter type which we tried to use. It failed because it kinda expands too early(?). Well, really LaTeX gets the argument which might be balanced braces or a single token, eventually that gets expanded. Using Expanded caused latexml to only see the 1st char of the expansion instead of the whole thing; adding extra braces mucked things up differently. It's probably true that one would need (at least) two separate flavors of "expanded"...

Copy link
Collaborator

Choose a reason for hiding this comment

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

Right, it looks like we need a ->readXArg rather than a ->readXToken, and since we don't have that yet, the current PR makes sense

Copy link
Collaborator

Choose a reason for hiding this comment

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

But this begs the question if the Expanded parameter type is ever the correct type to use? Maybe it just needs an upgrade, even separately from the \begin case.

my $before = LookupValue('@environment@' . $name . '@beforebegin');
my $after = LookupValue('@environment@' . $name . '@atbegin');
if (IsDefined("\\begin{$name}")) {
(($before ? @$before : ()),
T_CS("\\begin{$name}")); } # Magic cs!
Expand All @@ -162,9 +162,9 @@ DefMacro('\begin{}', sub {

DefMacro('\end{}', sub {
my ($gullet, $env) = @_;
my $name = $env && ToString($env);
my $before = LookupValue('@environment@' . ToString($_[1]) . '@atend');
my $after = LookupValue('@environment@' . ToString($_[1]) . '@afterend');
my $name = $env && ToString(Expand($env));
my $before = LookupValue('@environment@' . $name . '@atend');
my $after = LookupValue('@environment@' . $name . '@afterend');
my $t;

if (IsDefined($t = T_CS("\\end{$name}"))) {
Expand Down
Binary file modified t/expansion/environments.pdf
Binary file not shown.
18 changes: 18 additions & 0 deletions t/expansion/environments.tex
Expand Up @@ -20,4 +20,22 @@
A Quote!
\end{quote1}

\def\foo{quote}
\begin\foo
a + b
\end\foo

\begin{\foo}
a + b
\end{\foo}

\def\foo{equation}
\begin\foo
a + b
\end\foo

\begin{\foo}
a + b
\end{\foo}

\end{document}
44 changes: 44 additions & 0 deletions t/expansion/environments.xml
Expand Up @@ -27,4 +27,48 @@ A Quote!</p>
A Quote!</p>
</quote>
</para>
<para xml:id="p5">
<quote>
<!-- %**** environments.tex Line 25 **** --> <p>a + b</p>
</quote>
</para>
<para xml:id="p6">
<quote>
<p>a + b</p>
</quote>
</para>
<para xml:id="p7">
<equation xml:id="S0.E1">
<tags>
<tag>(1)</tag>
<tag role="refnum">1</tag>
</tags>
<Math mode="display" tex="a+b" text="a + b" xml:id="S0.E1.m1">
<XMath>
<XMApp>
<XMTok meaning="plus" role="ADDOP">+</XMTok>
<XMTok font="italic" role="UNKNOWN">a</XMTok>
<XMTok font="italic" role="UNKNOWN">b</XMTok>
</XMApp>
</XMath>
</Math>
</equation>
</para>
<para xml:id="p8">
<equation xml:id="S0.E2">
<tags>
<tag>(2)</tag>
<tag role="refnum">2</tag>
</tags>
<Math mode="display" tex="a+b" text="a + b" xml:id="S0.E2.m1">
<XMath>
<XMApp>
<XMTok meaning="plus" role="ADDOP">+</XMTok>
<XMTok font="italic" role="UNKNOWN">a</XMTok>
<XMTok font="italic" role="UNKNOWN">b</XMTok>
</XMApp>
</XMath>
</Math>
</equation>
</para>
</document>