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

simple macro with \section fails to compile... unless written in xml flavour #535

Closed
be1 opened this issue Jul 7, 2018 · 4 comments · Fixed by #863
Closed

simple macro with \section fails to compile... unless written in xml flavour #535

be1 opened this issue Jul 7, 2018 · 4 comments · Fixed by #863
Labels
bug Software bug issue
Milestone

Comments

@be1
Copy link

be1 commented Jul 7, 2018

when using the folowing macro:

\define[command=mois]{\section[numbering=no]{\process}}

sile fails by:

Error detected:
/usr/local/share/sile/core/inputs-common.lua:26: bad argument #1 to 'ipairs' (table expected, got nil)

mois.txt

in xml the compilation works nice.

<define command="mois">
<section numbering="no"><process/></section>
</define>

<mois>Juillet</mois>
@simoncozens
Copy link
Member

I know why this is happening. I am not sure why it is not happening with XML. It should still be broken with XML! What's going on is that:

  • \mois puts its content ("Juillet") onto the macro stack.
  • \section displays the section title, using the contents of the \section command as its title. The contents in this case is \process, so the \process command is evaluated.
  • \process pops "Juillet" off the macro stack and hands it to book:sectionfont.
  • \section sets up the running header, using the contents of the \section command as the running head. The contents of \section is still \process, so the \process command is evaluated again.
  • \process tries to pop the macro stack, but now it's empty, so you get a stack underflow.

In essence, not only can \process only be used once in a macro, it can only be used once in anything that macro calls. I sort of regret providing the macro functionality; it's really half-baked and leads to all kinds of trouble. Where you can, stick to Lua for declaring SILE commands.

I'm not sure what the right answer is to this, other than maybe rewrite how \process works. Maybe looking at why the XML version works would be useful.

@alerque
Copy link
Member

alerque commented Jul 8, 2018

For reference, here's how to do this in Lua.

SILE.registerCommand("mois", function (options, content)
  SILE.call("section", { numbering = false }, content)
end)

Of course it's best if you stick this sort of thing in a separate Lua file, but if you need to stick this in your document your can do it inline as well. In XML:

<script>
   <!--- Lua code here -->
</script>

The current SILE release doesn't have the parsing chops to do this in TeX-like markup, but the the development version does. You can do this:

\begin{script}
   -- Lua code here
\end{script}

Even better, if this is always the way you want too call \section, then the use case of using a standard command but redefining the default arguments is a very common one and if you are using the development version of SILE I have added a shortcut for this. Check out the setCommandDefaults() function.

SILE.setCommandDefaults("section", { numbering = false })

Then you can keep using the \section command and always get that option set by default.

@be1
Copy link
Author

be1 commented Jul 8, 2018

Thank you for your replies.
@simoncozens i refined the test, and actually the xml flavour fails too hen used in a simple test file but works in a complex longer document when used as is:

<chapter>The chapter</chapter>

<mois>Juillet</mois>

@alerque Thank you, i wil luse lua scripts then, avoiding macros.

@OlivierNicole
Copy link
Member

OlivierNicole commented Apr 30, 2020

Edit: Please ignore this, it’s unrelated, I just didn’t know my included file should have a \sile root tag.

Just stumbled upon a variant of this. \includeing a .sil file containing:

\define[command=code]{\font[family=DejaVu Sans Mono, size=1.5ex]{\process}}

gives a stack underflow error, but including the same file in XML format doesn’t. Inlining the .sil file also removes the error. Quite puzzling.

@alerque alerque added the bug Software bug issue label Apr 30, 2020
@alerque alerque added this to the v0.11.0 milestone Apr 30, 2020
OlivierNicole added a commit to OlivierNicole/sile that referenced this issue May 1, 2020
OlivierNicole added a commit to OlivierNicole/sile that referenced this issue May 2, 2020
OlivierNicole added a commit to OlivierNicole/sile that referenced this issue May 2, 2020
@alerque alerque modified the milestones: v0.11.0, v0.10.5 May 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Software bug issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants