oscarlevin / pretext-tools

MIT License
7 stars 9 forks source link

Bug: <xi:include> not allowed here #46

Closed FelixBenning closed 1 year ago

FelixBenning commented 1 year ago

Reproduction: Creating a new pretext project with

pretext new article

immediately results in the error

element "xi:include" not allowed anywhere; expected element "activity", "algorithm", "aside", "assemblage", "assumption", "axiom", "biographical", "blockquote", "claim", "commentary", "computation", "conjecture", "console", "convention", "corollary", "data", "definition", "demonstration", "example", "exercise", "exploration", "fact", "figure", "fragment", "frontmatter", "heuristic", "historical", "hypothesis", "identity", "idx", "image", "insight", "introduction", "investigation", "lemma", "list", "list-of", "listing", "note", "objectives", "observation", "p", "paragraphs", "plaintitle", "poem", "pre", "principle", "problem", "program", "project", "proof", "proposition", "question", "remark", "sage", "sbsgroup", "section", "shorttitle", "sidebyside", "subtitle", "table", "tabular", "technology", "theorem", "video" or "warning"

I am assuming that the schema is incomplete

oscarlevin commented 1 year ago

Try this. In vs code's settings (ctrl+,) search for xml validation. Make sure that Xml > Validation > XInclude: Enabled is checked. This should allow the schema checker to follow xi:include calls.

angelozerr commented 1 year ago

Im not sure that it will fix the problem, I suspect that it is a problem with the rng schema

FelixBenning commented 1 year ago

Try this. In vs code's settings (ctrl+,) search for xml validation. Make sure that Xml > Validation > XInclude: Enabled is checked. This should allow the schema checker to follow xi:include calls.

It is checked. It also says: "Default Value overridden by PreTeXt tools" on hover. So it looks like this works as expected.

angelozerr commented 1 year ago

@FelixBenning can you share your XML file please.

FelixBenning commented 1 year ago

sure (as I said they are the result of pretext new article, but here are the files

<!-- main.ptx -->
<?xml version='1.0' encoding='utf-8'?>
<pretext xml:lang="en-US" xmlns:xi="http://www.w3.org/2001/XInclude">
  <docinfo>
    <macros>\newcommand{\foo}{b^{ar}}</macros>
    <latex-image-preamble>\usepackage{tikz}</latex-image-preamble>
  </docinfo>
  <article xml:id="my-great-article">
    <title>My Great Article</title>
    <xi:include href="./section-1.ptx" />
    <xi:include href="./section-2.ptx" />
  </article>
</pretext>
<!-- section-1.ptx -->
<?xml version='1.0' encoding='utf-8'?>
<section xml:id="section-1" xmlns:xi="http://www.w3.org/2001/XInclude">
  <title>My First Section</title>
  <introduction>
    <p>Some words</p>
  </introduction>
  <p>foo</p>
  <figure>
    <caption>A frog</caption>
    <image source="frog.jpg" width="50%">
      <description>A nice-looking frog with a longish
      description.</description>
    </image>
  </figure>
  <p>Bar:
  <m>\foo</m></p>
</section>
<!-- section-2.ptx -->
<?xml version='1.0' encoding='utf-8'?>
<section xml:id="section-2" xmlns:xi="http://www.w3.org/2001/XInclude">
  <title>My Additional Section</title>
  <introduction>
    <p>Other words</p>
  </introduction>
  <p>foo</p>
  <figure xml:id="figure-tikz-example-diagram">
    <caption>The graph <m>C_5</m> made by TikZ</caption>
    <image xml:id="tikz-example-diagram" width="20%">
      <description>A 5-cycle</description>
      <latex-image>
            \begin{tikzpicture}
              \coordinate (A) at (90+360/5:1);
              \coordinate (B) at (90+2*360/5:1);
              \coordinate (C) at (90+3*360/5:1);
              \coordinate (D) at (90+4*360/5:1);
              \coordinate (E) at (90:1);

              \draw (A) -- (B) -- (C) -- (D) -- (E) -- (A);
              \foreach \x in {(A), (B), (C), (D), (E)}{
                \fill \x circle (2pt);
              }
            \end{tikzpicture}
      </latex-image>
    </image>
  </figure>
  <p>bar</p>
</section>
angelozerr commented 1 year ago

sure (as I said they are the result of pretext new article, but here are the files

I'm one of the author of vscode-xml and I have never used pretex. Thanks for sharing your files.

@oscarlevin was right, you need to configure XInclude. See https://github.com/redhat-developer/vscode-xml/blob/main/docs/Features/XIncludeFeatures.md

See following demo here:

XIncludePretext

FelixBenning commented 1 year ago
Screenshot 2023-07-16 at 13 16 51

as I said it is already enabled. The default is set to true by pretext-tools

angelozerr commented 1 year ago

Which pretext.rng file are you using?

FelixBenning commented 1 year ago

What is a pretext.rng file?

oscarlevin commented 1 year ago

I am not able to reproduce this error. Two things to check:

  1. What version of pretext-tools are you using? There was a bug someone pointed out in 0.11.2, which was fixed in 0.11.3.
  2. If you go to settings, search "pretext" you will see an option for Schema Version. I don't think it matters whether you use the Stable or Experimental version for this issue, but you could try switching it and reloading your workspace (by restarting vs code, for example). The schema version says which .rng file you use. (You can see this inside the .vscode/settings.json file)
FelixBenning commented 1 year ago

pretext-tools is v0.11.3. I just tried pretext for the first time so this was a new installation. It was on stable but experimental does not work either.

With the .vscode/settings.json do you mean the user settings JSON? because I couldn't find any reference to an .rng file in there. If I click on "copy settings as JSON" in the ui I get

"pretext-tools.schemaVersion": "Stable"
oscarlevin commented 1 year ago

Inside your project folder, there should be a .vscode folder that contains a file settings.json. The contents of that file, for me, is

{
  "xml.fileAssociations": [
    {
      "pattern": "**/source/**.ptx",
      "systemId": "/home/oscar/.ptx/schema/pretext-dev.rng"
    }
  ]
}

The only other thing I can think of is that there is something strange going on with your settings between User and Workspace (in the settings window, you should see both of these at the top; I think the idea is that a particular project can have different settings from your global (i.e., user) settings.)

FelixBenning commented 1 year ago

ah, right found it:

{
  "xml.fileAssociations": [
    {
      "pattern": "**/source/**.ptx",
      "systemId": "/Users/fbenning/.ptx/schema/pretext.rng"
    }
  ]
}

I also checked that the file is there. It also switches to pretext-dev.rng when I set the setting to experimental and reload.

angelozerr commented 1 year ago

@FelixBenning to know which schema you are using in your ptx file, I suggest that you enable codelens on XML side https://github.com/redhat-developer/vscode-xml/blob/main/docs/Preferences.md#code-lens

After that you will see with file association codelens that you click on it to open the schema:

PtxCodeLensFileAssociation

FelixBenning commented 1 year ago

Found the "with file association setting"

Screenshot 2023-07-20 at 22 05 14

I pasted the entire schema into the collapsible below.

The schema ```xml Here is what a book looks like. all odd even codelens 2 3 4 5 6 2 3 4 5 6 disc circle square narrow medium wide yes no yes no 2d 3d yes no none minor medium major left center right justify top middle bottom yes no yes no embed popout select default generic 2 3 4 5 6 left center right raw bibtex The WeBWorK "var" element appears in the RELAX-NG schema as a child of many elements, but almost always as a descendant of a "p" element or a "cell" element. As an element that is only relevant for a WeBWorK problem, occurrences of "var" must be within a "webwork" element. A Schematron rule will check on these two situations. angle decimal exponent formula fraction inequality integer interval logarithm limit number point syntax quantity vector popup buttons checkboxes none essay local global hybrid type-local type-global type-hybrid phrase-global phrase-hybrid title custom yes no star dstar tstar dagger ddagger tdagger daggerdbl ddaggerdbl tdaggerdbl hash dhash thash maltese dmaltese tmaltese yes no yes no yes no yes no yes no 0 1 2 3 4 5 6 7 8 9 10 A B C D E F G a b c d e f g 1 2 3 4 5 6 7 8 9 10 doublesharp sharp flat doubleflat 1 2 3 4 5 yes no yes no yes no short long decorative structural ```
FelixBenning commented 1 year ago

So I get the same behaviour on my windows PC at home and my work mac laptop. So I am really confused that you can not reproduce. If you want to hop on a call for debugging, I can probably make time.

angelozerr commented 1 year ago

Ok I think you are using vscode-xml in binary mode (I think you have not Java which is installed, so it use binary mode) and after testing vscode-xml in binary mode, I noticed the same problem than you.

I created the issue https://github.com/redhat-developer/vscode-xml/issues/922 and start a quick fix.

FelixBenning commented 1 year ago

I indeed did not have java installed. I just installed it - but after restarting vscode I still have the same error.

angelozerr commented 1 year ago

I think you are using binary again. You need to configure Java home, see https://github.com/redhat-developer/vscode-xml/blob/main/docs/Preferences.md#java-home

and check xml.server.preferBinaryis not set to true https://github.com/redhat-developer/vscode-xml/blob/main/docs/Preferences.md#server-binary-mode

FelixBenning commented 1 year ago

setting the path indeed fixed the issue ✔️

angelozerr commented 1 year ago

@FelixBenning the fix for binary has been merged. Could you tomorrow (when the vscode-xml prerelease will be available) try:

Thanks!

FelixBenning commented 1 year ago

unfortunately it seems to still be an issue

Screenshot 2023-07-25 at 10 01 52

(maybe I was too early)

angelozerr commented 1 year ago

(maybe I was too early)

Yes I think so, the version should be v0.26.2023072504, in your case you have installed "v0.26.2023072004"

Could you retry to install it please.

FelixBenning commented 1 year ago

it does work now 👍

angelozerr commented 1 year ago

Great! Thanks for your patience.

FelixBenning commented 1 year ago

What patience 😄 just two weeks turn around time is fantastic for a free open source project. Thank you for your help!

angelozerr commented 1 year ago

Glad you enjoy with pretext-tools / vscode-xml. We are happy that @oscarlevin decided to be based on vscode-xml.

For your information if you are working on xref / @xml:id, the pretext tools configure vscode-xml to enable it, you should benefit with completion, validation,hyperlink, rename, etc, see https://github.com/redhat-developer/vscode-xml/blob/main/docs/Features/XMLReferencesFeatures.md#attribute-node-references-fooattr