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

\ref{} is detected as end of a sentence #168

Closed
atsuyaw opened this issue May 26, 2021 · 6 comments · Fixed by #181
Closed

\ref{} is detected as end of a sentence #168

atsuyaw opened this issue May 26, 2021 · 6 comments · Fixed by #181
Labels
bug Something isn't working

Comments

@atsuyaw
Copy link

atsuyaw commented May 26, 2021

When I use \ref{}, the command was detected as end of a sentence:
image

It is expected to detect an error in sentences such as line 199, but errors outed in line 200 and 201.

\ref{} command is used for cross-reference frequently in academic writing.
In fact, such structure of sentences were contained a lot in my file, so the output were filled with these errors.

@pddg pddg added the unconfirmed This needs to be confirmed by maintainers label Jun 6, 2021
@pddg
Copy link
Member

pddg commented Jun 6, 2021

@atsuyaw
Thank you for reporting the issue. I confirmed that it is a bug.
Sorry for the delay in addressing the other reported issues 😥 .
We will do our best to fix it.

@pddg pddg added bug Something isn't working and removed unconfirmed This needs to be confirmed by maintainers labels Jun 6, 2021
@pddg
Copy link
Member

pddg commented Jun 6, 2021

How to reproduce

Environment

  • Node.js v14.17.0
  • textlint-plugin-latex2e v1.1.3
  • textlint v12.0.0
  • textlint-rule-ja-no-mixed-period v2.1.1

Procedure

$ mkdir textlint-latex2e-issue168 && cd $_
$ npm init -y
$ npm install --save \
    [email protected] \
    [email protected] \
    [email protected]
$ cat << EOF > sample.tex
本日は図\ref{fig:sunnyy}に示すように晴天なり。
EOF
$ cat << EOF > .textlintrc
{
    "plugins": ["latex2e"],
    "rules": {
        "ja-no-mixed-period": {
            "periodMark": "。"
        }
    }
}
EOF
$ textlint sample.tex

/Users/pudding/Factory/textlint-latex2e-issue168/sample.tex
  1:4  error  文末が""で終わっていません。  ja-no-mixed-period

✖ 1 problem (1 error, 0 warnings)

Cause of this issue

There seems to be an error in the way Paragraph is interpreted. There should be an inline node and a block node, but since \ref is interpreted as a block node, there are two separate Paragraphs, which should be one.

$ npx tex2tast -r sample.tex
{
  "type": "Document",
  "raw": "本日は図\\ref{fig:sunnyy}に示すように晴天なり。\n",
  "children": [
    {
      "raw": "本日は図",
      "type": "Paragraph",
      "children": [
        {
          "raw": "本日は図",
          "type": "Str",
          "value": "本日は図"
        }
      ]
    },
    {
      "raw": "\\ref{fig:sunnyy}",
      "value": "fig:sunnyy",
      "type": "Html"
    },
    {
      "raw": "に示すように晴天なり。",
      "type": "Paragraph",
      "children": [
        {
          "raw": "に示すように晴天なり。",
          "type": "Str",
          "value": "に示すように晴天なり。"
        }
      ]
    }
  ]
}

This problem can be avoided by interpreting it as an inline element, just like label and url.

@pddg
Copy link
Member

pddg commented Jun 6, 2021

hmm...

This problem is caused by #70 . HTML type nodes contain two types, inline and block, but there is no way to tell the difference, so they are always interpreted as block elements.

for (const node of rootNode.children) {
switch (node.type) {
case ASTNodeTypes.CodeBlock:
case ASTNodeTypes.Header:
case ASTNodeTypes.Html:
pushChild(paragraph);
paragraph = [];
children.push(node);
break;
case "parbreak":
pushChild(paragraph);
paragraph = [];
break;
default:
paragraph.push(node);
}
}

@tani Do you know of any good solutions?

@pddg
Copy link
Member

pddg commented Jun 6, 2021

Oh, I found HtmlBlock in ASTNodeTypes definitions.

https://github.com/textlint/textlint/blob/master/packages/%40textlint/ast-node-types/src/index.ts#L26

We need to use both Html and HtmlBlock.

@pddg
Copy link
Member

pddg commented Jun 12, 2021

@atsuyaw
We published a new version of textlint-plugin-latex2e v1.1.4. It includes some fixes for #158 and this issue.
Please check and let me know if there are any bugs. Thank you!

@atsuyaw
Copy link
Author

atsuyaw commented Jun 13, 2021

@pddg
Thank you for your corresponding!
I confirmed the problems solved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants