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

Subsection not being child of Section inspection #1492

Merged

Conversation

Xaaris
Copy link
Contributor

@Xaaris Xaaris commented Jun 20, 2020

Inspection notices misplaced section and paragraph commands and offers quickfix

Fixes #1490

Summary of additions and changes

At first I thought it would be more straight forward, but the more I thought about it the more exceptions there are. But please tell me if you see a simpler solution.
I wasn't able to just use the Magic.Command.labeledLevels as it is e.g. okay (correct me if I'm wrong) to have a paragraph after a section. Also part and chapter are optional.

This now basically just tests that a document does not start with a subsection, subsubsection or subparagraph, that a subsubsection does not follow directly after a subsection and that a subparagraph follows another subparagraph or a paragraph.

How to test this pull request

Some tests are included

Wiki

Copy link
Collaborator

@PHPirates PHPirates left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! I will look at it in more detail later, but here are already a few comments:

  • Perhaps you can make it a weak warning (or info, I forgot how it's called) instead of a warning, because it's not really a LaTeX warning but more like a convention
  • Can you also provide a quickfix to replace the sectioning command by the right level, in addition to the quickfix inserting the extra levels?
  • I actually would restrict this to sectioning commands in the file, because this should not trigger a warning:

main.tex:

\documentclass{article}
\begin{document}
    \section{One}
    \input{section1}
\end{document}

section1.tex:

\subsection{Subsection 1}

Of course ideally you want to take into account al those includes too, but I think it might make the inspection too slow (or too complicated) for now.

@Xaaris
Copy link
Contributor Author

Xaaris commented Jun 21, 2020

I implemented your first two suggestions.
I'm not sure about the third one though. The LatexCommandsIndex.getCommandsByNames() is given a file already, so I assume that it is file specific already. Nevertheless, your example above would still show a warning as the section1.tex document does not start with a top-level section command. Should I just delete that check? I would assume it to have more true positives and the false positive case mentioned above to be quite seldom? But any false positives are annoying for sure, no matter how seldom they appear

@PHPirates
Copy link
Collaborator

Great, thanks!
Yeah, that's what I meant, you could delete that check - unless you want to fix the false positive properly, which is more work but of course better. I guess you could do it by retrieving the including files from the fileset cache, then the commands from the including file, and check how the include commands appears within the sectioning commands.
I think the case I mentioned is not so rare: a lot of people split up files according to sections, and at least I always do that as well.

I just took a better look at the inspection, I agree to keep the paragraph separate but I wonder why you only check for subsubsection after section? Why not also check for subsection or subsubsection after chapter or part? (In this case, instead of checking the documentclass you could just assume part is level 0 to avoid false positives).
If you do change it, perhaps mapping commands (except (sub)paragraph) to level and then checking the difference might be easier.

@PHPirates PHPirates added this to the b0.7 milestone Jun 21, 2020
@Xaaris
Copy link
Contributor Author

Xaaris commented Jun 23, 2020

Unfortunately I can't spent too much time on it at the moment to do the check through the whole file hierarchy as you suggested in your first paragraph. But I included \part and \chapter now. I tried but wasn't able to come up with nice way of mapping the commands to levels and then using basic math. There was always an edge case that broke it. Thats why I opted for the map of commands to forbidden predecessor commands. Tell me what you think about it

@PHPirates
Copy link
Collaborator

There was always an edge case that broke it. Thats why I opted for the map of commands to forbidden predecessor commands.

I agree this is better, it is immediately clear now when looking at the code what cases we check for.
I will look at this in more detail soon, but glancing over the code I think it's pretty much done now. We can do the file hierarchy checking later. Thanks for the help!

@PHPirates PHPirates marked this pull request as ready for review June 24, 2020 05:57
@PHPirates PHPirates merged commit ddb3790 into Hannah-Sten:master Jun 25, 2020
@Xaaris Xaaris deleted the Fix-#1490-incorrect-nesting-inspection branch June 26, 2020 12:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Subsection not being child of Section inspection
2 participants