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

\importmodule does not tolerate _ in module names #202

Closed
kohlhase opened this issue Jan 1, 2016 · 23 comments
Closed

\importmodule does not tolerate _ in module names #202

kohlhase opened this issue Jan 1, 2016 · 23 comments

Comments

@kohlhase
Copy link
Contributor

kohlhase commented Jan 1, 2016

\importmodule{test_test} gives me the error.

Error:unexpected:_ Script _ can only appear in math mode
    /Users/kohlhase/localmh/MathHub/MiKoMH/GenCS/source/dmath/en/test.tex#textrange(from=2;0,to=2;26)
    In Core::Definition::Primitive[Subscript] from TeX.pool.ltxml line 3488
     <= Core::Stomach[@0x7fac4db5c5b8] <= Core::Gullet[@0x7fac4a8505e0] <= Core::Stomach[@0x7fac4db5c5b8] <= ...

Just run sTeX on

\begin{module}[id=test]
  \importmodule{test_test}
\end{module}

I am not sure where this comes from, I had suspected that we have to give the argument of \importmodule the type Semivarbatim or even TeXFileName, but that did not really help.

@kohlhase kohlhase added the bug label Jan 1, 2016
@kohlhase kohlhase changed the title \gimport does not tolerate _ in module names \importmodule does not tolerate _ in module names Jan 1, 2016
@kohlhase
Copy link
Contributor Author

kohlhase commented Jan 1, 2016

@dginev, could you have a look at this?

@kohlhase
Copy link
Contributor Author

kohlhase commented Jan 1, 2016

this is important (priority) to me, since we need if of the OpenDreamKit flexiformalization of elliptic curves.

@dginev
Copy link
Contributor

dginev commented Jan 1, 2016

Can you easily use underscores in the TeX implementation? I was left with the impression they remain active unless explicitly neutralized. Active underscores are easily one of the most common problems in Authorea as well btw.

@kohlhase
Copy link
Contributor Author

kohlhase commented Jan 1, 2016

There does not seem to be a problem in sTeX here.

@kohlhase
Copy link
Contributor Author

kohlhase commented Jan 1, 2016

But the only thing that is really happening is that the arguments are passed around to an \input eventually, and (in a way that I do not really understand) into macro names.

@angerhang
Copy link

https://github.com/KWARC/LaTeXML/blob/master/lib/LaTeXML/Package/TeX.pool.ltxml#L3404-L3407
From this block, we can see that LaTeXML doesn't allow us to have ^ or _ in a non-math block for the argument.

I can think of two possible workarounds:

I. a sketchy approach: explicitly silencing this error for sTeX, which however, might introduce other errors and make KWARC's LaTeXML deviate from Bruce's branch.

II. a might work approach: without modifying any LaTeXML code, instead of passing the module name by argument, we can pass it by keyval e.g. \importmodule[modules = test_test] as LaTeXML doesn't check the scripts, _, ^ when they are passed.

Can @dginev and @kohlhase comment on this?

@dginev
Copy link
Contributor

dginev commented Jan 3, 2016

Right, you are pointing to the exact bit of code that triggers the error, when the underscore is expanded outside of math mode.

So the idea with the Semiverbatim parameter type is exactly to avoid that. It is a different reader than the Plain parameter one, which will slurp in characters a lot more leniently, and it would never treat the underscore as a primitive.

https://github.com/KWARC/LaTeXML/blob/master/lib/LaTeXML/Package/TeX.pool.ltxml#L237

If you could first change the plain argument {} to Semiverbatim in the DefConstructor here:
https://github.com/KWARC/sTeX/blob/master/sty/modules/modules.sty.ltxml#L123

and try using an underscore name, I would be quite curious to read more about what the error is and how it's triggered. It should "just work". I am equally surprised Michael has made this work in TeX so easily, since the catcode must have been neutralized there as well.

@dginev
Copy link
Contributor

dginev commented Jan 3, 2016

Btw, @kohlhase just a reminder that if you switch the \importmodule argument to Semiverbatim, you will no longer be able to expand macros in it, and I remember there used to be importmodule arguments that had macros (e.g. for instantiating the right relative path).

It may be better to use the dedicated TeXFileName parameter type here, but I would ask @brucemiller if that fits the intended use of that reader.

@angerhang
Copy link

Right,

DefConstructor('\importmodule OptionalKeyVals:importmodule Semiverbatim',

works on on

  \importmodule{test_test}

with no problem.

@dginev
Copy link
Contributor

dginev commented Jan 3, 2016

Perfect, then there is probably 0 dev work to do here. I am still wondering if using TeXFileName isn't better than Semiverbatim in this case.

@dginev
Copy link
Contributor

dginev commented Jan 3, 2016

Btw, @angerhang here is the intro-level documentation of binding "prototypes" where semiverbatim is briefly introduced: http://math.nist.gov/~BMiller/LaTeXML/manual/modules/LaTeXML_Package.html#SSx2.SSSx1.Px1

TeXFileName is not present in these docs, so @brucemiller could tell us if that is an intended or unintended omission :> But it's in TeX.pool so we can certainly use it.

@angerhang
Copy link

Yap thanks for the tip : )

but I don't know why Miko said neither Semivarbatim nor TeXFileName helped for him. Perhaps @kohlhase can also elaborate on this.

@kohlhase
Copy link
Contributor Author

kohlhase commented Jan 4, 2016

I probably had some problems testing, I was wondering myself. Did you commit?

@angerhang
Copy link

I haven't because Deyan and I were not sure if Semivarbatim or TeXFileName is better.

@kohlhase
Copy link
Contributor Author

kohlhase commented Jan 5, 2016

I am not sure either, so let's just start with Semiverbatim and then escalate to TeXFileName when necessary.

@kohlhase
Copy link
Contributor Author

kohlhase commented Jan 5, 2016

Note that we also need to do the same for \usemodule.

@brucemiller
Copy link

TeXFileName is probably not what you want: it reads the filename the TeX way: w/o braces, up to a space, cr or comment and doesn't accept macros. Semiverbatim is more likely what you want: it neutralizes ^,_,@,~,&,$,' and accepts control sequences and (depending on the caller) does accept expand them.

Note that up until a recent patch, % was also accepted, but that turns out to have been a mistake. (there are ways to get % accepted to, if you need).

@kohlhase
Copy link
Contributor Author

kohlhase commented Jan 5, 2016

Thanks to Bruce for the clarification. I had suspected something like this (you might still update the LaTeXML documentation though). And we definitely do not want TeXFileName it seems like.

@dginev
Copy link
Contributor

dginev commented Jan 5, 2016

All clear, thanks for the details!

@kohlhase
Copy link
Contributor Author

kohlhase commented Jan 5, 2016

@angerhang I have tested this with the modules at https://gl.mathhub.info/ODK/lmfdb/. And I am still getting script warnings. Could you please try as well? Just install them via lmh and that should be sufficient.

@angerhang
Copy link

I tried to install the modules by lmh install ODK but I get parsing failure:

lmh install ODK
'NoneType' object has no attribute 'find'
Parsing failure (make sure gl::projects_url is correct)

@kohlhase
Copy link
Contributor Author

this is a known issue of lmh. Just use git clone directly. BUT I have renamed all files away from _ (to make progress), so you will have to make your own test cases I fear.

@kohlhase
Copy link
Contributor Author

This issue was moved to slatex/LaTeXML-Plugin-sTeX#16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants