Skip to content

AutoCommands of greek letters adds a space after the letter. #43

Description

@somiaj

I have it setup so Greek letters like theta get turned into their symbol for my course that uses them. I wanted to write a problem in which I wanted to use theta' as a variable, but this doesn't work because MathQuill inserts a space so the parser reads theta ' and errors out on ' as an undefined character. If I don't use the AutoCommands to turn theta into its Greek letter the problem works as expected.

I haven't noticed any other issues with the PG parser with this extra space being added, so this is a rare use case issue.

Unsure if removing the space being inserted could cause other issues.

Activity

  1. somiaj commented on Apr 3, 2026

    @somiaj
    ContributorAuthor

    Note, I am able to work around this by adding a variable named theta '.

  2. drgrice1 commented on Apr 3, 2026

    @drgrice1
    SponsorMember

    This is how commands (things that start with backslash) have always been dealt with (auto commands are still commands). I think you are the only one that has really tried to do much with Greek letters in this way, and so there hasn't been much demand to really look into it.

    It should be okay to change the text method of the Variable class (on line 539 of src/commands/mathElements.ts to something like

    	text() {
    		let text = this.ctrlSeq;
    		if (text.startsWith('\\')) {
    			if (text.startsWith('\\operatorname{')) text = text.slice(14, text.length);
    			else text = text.slice(1, text.length);
    		}
    		if (text.endsWith(' ') || text.endsWith('}')) {
    			text = text.slice(0, -1);
    			if (
    				!(
    					this.right instanceof Bracket ||
    					this.right instanceof Fraction ||
    					this.right instanceof SupSub ||
    					(this.right instanceof VanillaSymbol && this.right.ctrlSeq === "'")
    				)
    			)
    				text += ' ';
    		}
    		return text;
    	}

    Currently the handling of a space at the end does not occur for commands because of the else clause. This would make that happen. At least the unit tests still are good with this. If this change is made, then there definitely need to be unit tests added for this. Unfortunately, there really aren't enough text unit tests. See the comment in the test/text-output.ts file on line 35. Text output was not something that the original MathQuill library really cared about and only partially implemented. It is our usage that made this much more important, and there is still a lot of work needed in adding appropriate unit tests for it.

  3. drgrice1 commented on Apr 3, 2026

    @drgrice1
    SponsorMember

    I think that another possibility is to switch to using unicode for Greek letters in the text output. You would have to define the variables using those unicode letters also (I think that can be done with MathObjects), or at least define unicode alternatives. That might be better. Then you don't need to worry about spacing since it is a single character.

  4. somiaj commented on Apr 3, 2026

    @somiaj
    ContributorAuthor

    I have been trying to use unicode as alias for my variables, but I have a lot of older problems without that setup, so changing to unicode would break multiple problems for me. That being said, I have written a patch but never submitted it to make PG automatically add the TeX and unicode alternative for Greek letter variables. If such a patch was in PG then using unicode would be less of a problem for me.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions