Bizarre assign/macro bug

I’ve encountered a really strange bug with potentially serious consequences, though unfortunately I can’t reproduce the most serious consequence I encountered (a crash while editing the file). Nonetheless, it happened, and I’m pretty sure it’s related to this more “minor” bug.

Sorry for the long post; I investigated it as best I could, and included all of that info here.


In the file included as plaintext at the bottom, \u should evaluate to a macro that takes a single argument and puts it between a floor bracket on the right and a ceiling bracket on the left (<assign|u|<macro|x|<around*|\<lceil\>|<arg|x>|\<rfloor\>>>>). Typing \u and hitting enter should produce ⌈⌋ with the cursor in between the brackets.

If you use this assign statement in a fresh file, it works as expected. But if you use it in this file, it produces a pale red question mark where the argument should be (as shown in the file). My understanding is that this is a consequence of <u> being mistakenly inserted instead of <u|>. If you put the cursor after the occurrence of ⌈?⌋ when viewing the included source in TeXmacs, you can reproduce this behavior. (Earlier, and you’re likely to be before the assign statement for u.)

So here’s the weird part. If you delete one of the preceding paragraph breaks, the behavior of the \u input changes and becomes “normal”. (I also see the view change and zoom out slightly; not sure if this is a clue as to what’s happening.)

There was also an assign statement in the preamble from when I was playing around with the “create macro” gui. In investigating this bug, I discovered that deleting that assign statement had no effect on the bug, but deleting the paragraph break that had appeared in the preamble did fix the \u problem. (So, if you’re wondering why there’s a stray paragraph break in the preamble, it’s because it was inserted by the macro-creator gui process, but then I manually deleted the assign statement to minimize the example.)

At least, this is what’s happening for me. Can someone else who’s on a mac reproduce this behavior with their installation, to make sure it’s not a local problem?

Thanks!

EDIT: There’s another weird thing in this file which I thought was related, but which is a separate bug. If you hit the right arrow key to navigate to the end of the file, your cursor turns into a green bar that stretches the length of the page vertically on the left side. This seems related to a different assign statement (for downwards) that comes after the ⌈?⌋, which is strangely inaccessible via arrow-key navigation despite being visible in the source. This seems to be because the assign statement is of the form <assign|downwards<math|>| ... >; the <math|> trips it up. All I can say is that this occurred through normal editing in TeXmacs, not through unusual editing of source as plaintext or anything like that, so a user can accidentally produce this strange “unreachable” assign statement and never be able to fix it within TeXmacs. Should I go to Savannah to post about this bug? It’s unlikely to happen, sure, but it happened naturally and without trying to me, and the crucial part is that I had to go into the plaintext source to fix my mistake, which I don’t think should happen. Deleting the downwards assign statement does not fix the \u bug, though.

assign-bug.tm as plaintext
<TeXmacs|2.1.1>

<style|generic>

<\body>
  <\hide-preamble>
    \;
  </hide-preamble>

  \;

  \;

  \;

  \;

  \;

  \;

  \;

  \;

  \;

  <assign|u|<macro|x|<around*|\<lceil\>|<arg|x>|\<rfloor\>>>>

  <u>

  <assign|downwards<math|>|<macro|x|<around*|\<lceil\>|<arg|x>|\<rfloor\>>>>
</body>

<\initial>
  <\collection>
    <associate|page-medium|papyrus>
  </collection>
</initial>

Hi @thorimur

Many thanks for your report!

I can’t reproduce the <u> turning “normal” by deleting a preceding paragraph break. Does it matter where you put your cursor and how you delete it (which key do you press? Do you make a selection with the mouse?).

Which TeXmacs version and OS are you using?

I can reproduce the green cursor problem. I’ve seen this kind of problem appear before, so it may be good to report it, now that there is a minimal example for it.

I have noticed some other strange behaviour. If I put the cursor at the very beginning of the document and press the backspace key, lines after the cursor are deleted. Normally nothing should be deleted. Can you reproduce this?

On a different theme, how did you manage to attach the file assign-bug.tm as plaintext?

Hi @jeroen, sorry for the late response!

Very strangely, I can no longer reproduce the existing <u> turning “normal” anymore either. I wonder if somehow other definitions for u were being “picked up” after floating around in the environment somehow? No idea—just grasping at straws for why it should suddenly be different! (I also could have sworn that I quit and restarted TeXmacs, so I’m not sure what happened.)

However, I’ve come up with a way to create a similar unusual change in behavior: \u's that are entered after deleting one of those paragraph breaks do suddenly begin to behave normally. The following demonstrates the current question-mark behavior (as a sort of “control”) as well as the newly “changed” behavior.

  1. Position the cursor just after ⌈?⌋, either by navigating with arrow keys or clicking with the mouse (but not so far that the cursor becomes green).

  2. Type \u and hit enter; this should produce another ⌈?⌋.

  3. Navigate backwards by pressing the left arrow key 4 times. The cursor should be just before (but not “on”) the occurrence of the assign statement.

  4. Hit backspace.

  5. Navigate forwards by pressing the right arrow key twice. The cursor should now be just before the first ⌈?⌋.

  6. Type \u and hit enter; a correct ⌈⌋ environment should be produced. (The other occurrences of ⌈?⌋ do not change.)

As far as I can tell, the mode of navigation doesn’t matter, and which of the paragraph breaks gets deleted doesn’t matter either (deleting a preceding one also changes the behavior)—nor does where the new \u is entered, as long as it is after the assign statement. But I just wanted to provide a specific way to reproduce this.

For the record, I’m on TeXmacs 2.1.1, macOS Monterey 12.5.


I can indeed reproduce the “lines after the cursor being deleted when pressing backspace at the beginning” behavior that you’ve found! Very odd!

I simply opened my assign-bug.tm file in a plaintext editor, then copied that text here under a summary tag—and used a code block inside that summary tag! :slight_smile: (To insert a summary tag in the forum post editor, click the gear in the bar just above the text field, then click “hide details” to get a template; to get a code block use three backticks before and after the text on separate lines, as usual!)

1 Like