Loading ...
Sorry, an error occurred while loading the content.

better recognising of tex vs plaintex filetype

Expand Messages
  • Stefano Zacchiroli
    [ Forwarded to vim-dev, as requested by Bram. Consider both the patch and the suggested default change as RFCs ] Hi Bram, could you please consider the
    Message 1 of 11 , Aug 25, 2006
    • 0 Attachment
      [ Forwarded to vim-dev, as requested by Bram. Consider both the patch
      and the suggested default change as RFCs ]

      Hi Bram,
      could you please consider the attached patch for filetype.vim? It
      provides better recognition of 'tex' filetypes against 'plaintex' ones.
      It looks for sectioning commands that are specific to latex (\part,
      \section, \paragraph, ...).

      Also, according to a comment in filetype.vim, the code distinguishing
      between 'tex' and 'plaintex' should default to 'tex', whereas, according
      to these lines:

      " Default value, may be changed later:
      let format = exists("g:tex_flavor") ? g:tex_flavor : 'plain'

      I assume it defaults to 'plaintex'. Is there a reason for that or it is
      just a typo? I found the default to 'tex' much more reasonable, as most
      of people write latex these days ...

      What about changing it so that it matches the comment?

      Many thanks in advance,
      Cheers.

      --
      Stefano Zacchiroli -*- Computer Science PhD student @ Uny Bologna, Italy
      zack@{cs.unibo.it,debian.org,bononia.it} -%- http://www.bononia.it/zack/
      If there's any real truth it's that the entire multidimensional infinity
      of the Universe is almost certainly being run by a bunch of maniacs. -!-
    • Giuseppe Bilotta
      ... I don t think this is correct: these commands can be defined (and therefore appear) in plain TeX documents too (defined by the document writer), and they
      Message 2 of 11 , Aug 25, 2006
      • 0 Attachment
        On Sat, 26 Aug 2006 01:38:11 +0200, Stefano Zacchiroli wrote:

        > [ Forwarded to vim-dev, as requested by Bram. Consider both the patch
        > and the suggested default change as RFCs ]
        >
        > Hi Bram,
        > could you please consider the attached patch for filetype.vim? It
        > provides better recognition of 'tex' filetypes against 'plaintex' ones.
        > It looks for sectioning commands that are specific to latex (\part,
        > \section, \paragraph, ...).

        I don't think this is correct: these commands can be defined (and
        therefore appear) in plain TeX documents too (defined by the document
        writer), and they are defined by other TeX formats too (eplain and
        AMS-TeX, for example). Moreover, LaTeX requires these to appear before
        \begin{document}: in a LaTeX document there is some possibility of
        them appearing before only within a definition or somesuch, in which
        case \newcommand & similia will appear before.

        --
        Giuseppe "Oblomov" Bilotta

        Hic manebimus optime
      • Stefano Zacchiroli
        ... Good point. Still, with the current situation, working with long latex document, likely to be split in several files which are included from a single on,
        Message 3 of 11 , Aug 26, 2006
        • 0 Attachment
          On Sat, Aug 26, 2006 at 08:42:39AM +0200, Giuseppe Bilotta wrote:
          > I don't think this is correct: these commands can be defined (and
          > therefore appear) in plain TeX documents too (defined by the document
          > writer), and they are defined by other TeX formats too (eplain and
          > AMS-TeX, for example). Moreover, LaTeX requires these to appear before
          > \begin{document}: in a LaTeX document there is some possibility of
          > them appearing before only within a definition or somesuch, in which
          > case \newcommand & similia will appear before.

          Good point.

          Still, with the current situation, working with long latex document,
          likely to be split in several files which are \included from a single
          on, is annoying.

          The reason being that the included files do not have a preamble, and the
          recognition of 'tex' vs 'plaintex' is mainly based on stuff to appear in
          preamble. Note that not recognizing files as 'tex' properly will inhibit
          an important plugin as the vim latex suite to be loaded automatically.

          Maybe is just a matter of changing the default to 'tex' then?
          I tend to believe that the vast majority of documents in some \TeX
          dialect authored these day are \LaTeX ones ...

          Cheers.

          --
          Stefano Zacchiroli -*- Computer Science PhD student @ Uny Bologna, Italy
          zack@{cs.unibo.it,debian.org,bononia.it} -%- http://www.bononia.it/zack/
          If there's any real truth it's that the entire multidimensional infinity
          of the Universe is almost certainly being run by a bunch of maniacs. -!-
        • Giuseppe Bilotta
          ... Ow, right, I hadn t thought of that. Well, one might then work on the assumption that part/ chapter/ (sub)*section is the first command sequence of an
          Message 4 of 11 , Aug 27, 2006
          • 0 Attachment
            On Sat, 26 Aug 2006 10:30:43 +0200, Stefano Zacchiroli wrote:

            > Still, with the current situation, working with long latex document,
            > likely to be split in several files which are \included from a single
            > on, is annoying

            Ow, right, I hadn't thought of that.

            Well, one might then work on the assumption that
            \part/\chapter/\(sub)*section is the first command sequence of an
            included LaTeX document, so the detection algorithm in this case
            should be tuned differently.

            --
            Giuseppe "Oblomov" Bilotta

            "I weep for our generation" -- Charlie Brown
          • Benji Fisher
            ... I believe that Bram does not use any version of TeX himself. I maintain the plaintex and latex ftplugins, and I suggested the current detection scheme
            Message 5 of 11 , Aug 29, 2006
            • 0 Attachment
              On Sat, Aug 26, 2006 at 01:38:11AM +0200, Stefano Zacchiroli wrote:
              > [ Forwarded to vim-dev, as requested by Bram. Consider both the patch
              > and the suggested default change as RFCs ]
              >
              > Hi Bram,
              > could you please consider the attached patch for filetype.vim? It
              > provides better recognition of 'tex' filetypes against 'plaintex' ones.
              > It looks for sectioning commands that are specific to latex (\part,
              > \section, \paragraph, ...).
              >
              > Also, according to a comment in filetype.vim, the code distinguishing
              > between 'tex' and 'plaintex' should default to 'tex', whereas, according
              > to these lines:
              >
              > " Default value, may be changed later:
              > let format = exists("g:tex_flavor") ? g:tex_flavor : 'plain'
              >
              > I assume it defaults to 'plaintex'. Is there a reason for that or it is
              > just a typo? I found the default to 'tex' much more reasonable, as most
              > of people write latex these days ...
              >
              > What about changing it so that it matches the comment?
              >
              > Many thanks in advance,
              > Cheers.

              I believe that Bram does not use any version of TeX himself. I
              maintain the plaintex and latex ftplugins, and I suggested the current
              detection scheme (after a RFC before vim 7.0 was released). If the
              comments, documentation, and code do not agree, it is probably my fault.

              I do not think there is any reliable way to distinguish between
              plain TeX and LaTeX. After my RFC, I decided to treat plain TeX as the
              default, since it is the more basic, even though I agree that LaTeX is
              probably far more common now. I suggest adding

              let tex_flavor = "latex"

              to your vimrc file.

              HTH --Benji Fisher
            • Stefano Zacchiroli
              ... Hi Benji, thanks for your feedback. In my mail I was more talking as the maintainer of the vim package (and of the vim-latexsuite add-on), than as a vim
              Message 6 of 11 , Aug 29, 2006
              • 0 Attachment
                On Tue, Aug 29, 2006 at 03:06:39PM -0400, Benji Fisher wrote:
                > I do not think there is any reliable way to distinguish between
                > plain TeX and LaTeX. After my RFC, I decided to treat plain TeX as the
                > default, since it is the more basic, even though I agree that LaTeX is
                > probably far more common now. I suggest adding
                >
                > let tex_flavor = "latex"
                >
                > to your vimrc file.

                Hi Benji, thanks for your feedback.

                In my mail I was more talking as the maintainer of the vim package (and
                of the vim-latexsuite add-on), than as a vim user. Since I've been
                bugged by users asking for more recognition of LaTeX I was wondering if
                you agree to change the vim-wide default, instead of changing it on a
                per-user basis.

                Since you agree that LaTeX is more common, what is exactly your argument
                against having it as the default?

                Beside that, I agree with the other proposal in this thread of
                recognizing as LaTeX files which starts with a sectioning command (after
                several possible blanks of course), and I'm going to implement it.

                Any comments on that choice?

                Many thanks for your reply,
                Cheers.

                --
                Stefano Zacchiroli -*- Computer Science PhD student @ Uny Bologna, Italy
                zack@{cs.unibo.it,debian.org,bononia.it} -%- http://www.bononia.it/zack/
                If there's any real truth it's that the entire multidimensional infinity
                of the Universe is almost certainly being run by a bunch of maniacs. -!-
              • Benji Fisher
                ... If you maintain a vim package (for Debian, guessing from your sig?), then you can always define g:tex_flavor in a system vimrc if you want. BTW, the
                Message 7 of 11 , Aug 30, 2006
                • 0 Attachment
                  On Tue, Aug 29, 2006 at 09:16:41PM +0200, Stefano Zacchiroli wrote:
                  > On Tue, Aug 29, 2006 at 03:06:39PM -0400, Benji Fisher wrote:
                  > > I do not think there is any reliable way to distinguish between
                  > > plain TeX and LaTeX. After my RFC, I decided to treat plain TeX as the
                  > > default, since it is the more basic, even though I agree that LaTeX is
                  > > probably far more common now. I suggest adding
                  > >
                  > > let tex_flavor = "latex"
                  > >
                  > > to your vimrc file.
                  >
                  > Hi Benji, thanks for your feedback.
                  >
                  > In my mail I was more talking as the maintainer of the vim package (and
                  > of the vim-latexsuite add-on), than as a vim user. Since I've been
                  > bugged by users asking for more recognition of LaTeX I was wondering if
                  > you agree to change the vim-wide default, instead of changing it on a
                  > per-user basis.

                  If you maintain a vim package (for Debian, guessing from your
                  sig?), then you can always define g:tex_flavor in a system vimrc if you
                  want. BTW, the documentation for this is under

                  :help ft-tex-plugin

                  Having already made the decision one way after a RFC, I am reluctant to
                  reverse it. If I then get a rash of complaints from plain TeX and
                  conTeXt users, would I have to reverse it again?

                  > Since you agree that LaTeX is more common, what is exactly your argument
                  > against having it as the default?

                  Plain TeX came first, so it has priority. (Maybe LaTeX 2ε is an
                  independent format, but I remember when LaTeX first came out that it was
                  actually a bunch of \def's made on top of plain TeX.) This is the same
                  logic that leads to keeping vi-compatible regular expressions, despite
                  the persistent suggestions that vim adopt PCRE.

                  Defaults should cater to users who do simple things, and plain TeX
                  is simpler than LaTeX. Writing LaTeX and splitting your document among
                  multiple files (so that most of them do not have the \begin{document}
                  line) is complicated, and anyone doing this should be willing to
                  customize his or her vimrc file appropriately.

                  Please read the thread on this list started Mar 2, 2006, with the
                  subject

                  RFC: filetypes for TeX, LaTeX, ConTeXT (others?)

                  > Beside that, I agree with the other proposal in this thread of
                  > recognizing as LaTeX files which starts with a sectioning command (after
                  > several possible blanks of course), and I'm going to implement it.
                  >
                  > Any comments on that choice?

                  Do you mean you plan to implement it as a proposed modification to
                  $VIMRUNTIME/filetype.vim in the standard distribution, or a change to
                  your vim package? I agree with the comment that plain TeX users may
                  also define such sectioning commands. Maybe it would be safe if you
                  check for such definitions, using an include-file search ... but of
                  course, that is more convenient after ftplugin/plaintex.vim has been
                  :source'd.

                  HTH --Benji Fisher
                • Stefano Zacchiroli
                  ... Yes, sure, I was proposing it to you assuming it could have been an improvement for all users. In Debian we try to push upstream changes we think are
                  Message 8 of 11 , Aug 30, 2006
                  • 0 Attachment
                    On Wed, Aug 30, 2006 at 08:42:52AM -0400, Benji Fisher wrote:
                    > If you maintain a vim package (for Debian, guessing from your
                    > sig?), then you can always define g:tex_flavor in a system vimrc if you
                    > want. BTW, the documentation for this is under

                    Yes, sure, I was proposing it to you assuming it could have been an
                    improvement for all users. In Debian we try to push "upstream" changes
                    we think are useful. Of course if you don't agree on this change it is
                    pointless.

                    > > Since you agree that LaTeX is more common, what is exactly your argument
                    > > against having it as the default?
                    > Plain TeX came first, so it has priority. (Maybe LaTeX 2ε is an
                    > independent format, but I remember when LaTeX first came out that it was
                    > actually a bunch of \def's made on top of plain TeX.) This is the same
                    > logic that leads to keeping vi-compatible regular expressions, despite
                    > the persistent suggestions that vim adopt PCRE.

                    Ok, got it, I will then decide whether to change the default in Debian
                    depending on users willingness.

                    > Please read the thread on this list started Mar 2, 2006, with the
                    > subject
                    >
                    > RFC: filetypes for TeX, LaTeX, ConTeXT (others?)

                    Thanks for the pointer.

                    > > Beside that, I agree with the other proposal in this thread of
                    > > recognizing as LaTeX files which starts with a sectioning command (after
                    > > several possible blanks of course), and I'm going to implement it.
                    > >
                    > > Any comments on that choice?
                    >
                    > Do you mean you plan to implement it as a proposed modification to
                    > $VIMRUNTIME/filetype.vim in the standard distribution, or a change to
                    > your vim package?

                    In Debian we usually first implement changes as patches to our packages
                    and then try to push patches upstream, hoping to improve the life of
                    non-Debian users. So yes to both questions: first modifying our package,
                    than proposing the modification for the official
                    $VIMRUNTIME/filetype.vim.

                    > I agree with the comment that plain TeX users may
                    > also define such sectioning commands. Maybe it would be safe if you
                    > check for such definitions, using an include-file search ... but of
                    > course, that is more convenient after ftplugin/plaintex.vim has been
                    > :source'd.

                    I'm not really fond of plain TeX, but I think it is not really
                    widespread to \input slices of plain TeX. So the idea mentioned in this
                    thread was to implement the policy: "if a document starts with a lot of
                    blanks followed by one of the possible LaTeX sectioning commands, then
                    it is (probably) a LaTeX source file". What do you think of this policy?

                    Of course the comment about plain TeX coming first still applies, but
                    maybe you like this or have a better suggestion :-)

                    Cheers.

                    --
                    Stefano Zacchiroli -*- Computer Science PhD student @ Uny Bologna, Italy
                    zack@{cs.unibo.it,debian.org,bononia.it} -%- http://www.bononia.it/zack/
                    If there's any real truth it's that the entire multidimensional infinity
                    of the Universe is almost certainly being run by a bunch of maniacs. -!-
                  • Gautam Iyer
                    ... I actually like this policy a lot. Most people who break latex files up into tonnes and tonnes of little files, do so based on sections. Odds are, that the
                    Message 9 of 11 , Aug 30, 2006
                    • 0 Attachment
                      On Wed, Aug 30, 2006 at 07:17:16PM +0200, Stefano Zacchiroli wrote:

                      > > I agree with the comment that plain TeX users may also define such
                      > > sectioning commands. Maybe it would be safe if you check for such
                      > > definitions, using an include-file search ... but of course, that is
                      > > more convenient after ftplugin/plaintex.vim has been :source'd.
                      >
                      > I'm not really fond of plain TeX, but I think it is not really
                      > widespread to \input slices of plain TeX. So the idea mentioned in
                      > this thread was to implement the policy: "if a document starts with a
                      > lot of blanks followed by one of the possible LaTeX sectioning
                      > commands, then it is (probably) a LaTeX source file". What do you
                      > think of this policy?

                      I actually like this policy a lot. Most people who break latex files up
                      into tonnes and tonnes of little files, do so based on sections. Odds
                      are, that the little files will begin with a bunch of comments, and a
                      sectioning command.

                      It would make life easier if this made it into filetype.vim. Especially
                      because changing g:tex_flavor means that every time I edit a plain tex
                      file, I need to unlet this variable.

                      GI

                      --
                      'Common' Proof Techniques:
                      13. Proof by wishful citation -- The author cites the negation,
                      converse, or generalization of a theorem from the literature to support
                      his claims.
                    • A.J.Mechelynck
                      ... You can already implement that additional check by adding it (IIUC) in ~/.vim/after/filetype.vim (or, if you are a sysadmin, in
                      Message 10 of 11 , Aug 30, 2006
                      • 0 Attachment
                        Gautam Iyer wrote:
                        > On Wed, Aug 30, 2006 at 07:17:16PM +0200, Stefano Zacchiroli wrote:
                        >
                        >>> I agree with the comment that plain TeX users may also define such
                        >>> sectioning commands. Maybe it would be safe if you check for such
                        >>> definitions, using an include-file search ... but of course, that is
                        >>> more convenient after ftplugin/plaintex.vim has been :source'd.
                        >> I'm not really fond of plain TeX, but I think it is not really
                        >> widespread to \input slices of plain TeX. So the idea mentioned in
                        >> this thread was to implement the policy: "if a document starts with a
                        >> lot of blanks followed by one of the possible LaTeX sectioning
                        >> commands, then it is (probably) a LaTeX source file". What do you
                        >> think of this policy?
                        >
                        > I actually like this policy a lot. Most people who break latex files up
                        > into tonnes and tonnes of little files, do so based on sections. Odds
                        > are, that the little files will begin with a bunch of comments, and a
                        > sectioning command.
                        >
                        > It would make life easier if this made it into filetype.vim. Especially
                        > because changing g:tex_flavor means that every time I edit a plain tex
                        > file, I need to unlet this variable.
                        >
                        > GI
                        >

                        You can already implement that additional check by adding it (IIUC) in
                        ~/.vim/after/filetype.vim (or, if you are a sysadmin, in
                        $VIM/vimfiles/after/filetype.vim if you think all Vim users on your
                        system will profit by it).


                        Best regards,
                        Tony.
                      • Benji Fisher
                        ... I think my undergraduate thesis (1985, plain TeX, just about the time the first version of LaTeX came out) was structured that way (i.e., split into
                        Message 11 of 11 , Aug 31, 2006
                        • 0 Attachment
                          On Wed, Aug 30, 2006 at 10:36:09AM -0700, Gautam Iyer wrote:
                          > On Wed, Aug 30, 2006 at 07:17:16PM +0200, Stefano Zacchiroli wrote:
                          >
                          > > > I agree with the comment that plain TeX users may also define such
                          > > > sectioning commands. Maybe it would be safe if you check for such
                          > > > definitions, using an include-file search ... but of course, that is
                          > > > more convenient after ftplugin/plaintex.vim has been :source'd.
                          > >
                          > > I'm not really fond of plain TeX, but I think it is not really
                          > > widespread to \input slices of plain TeX. So the idea mentioned in
                          > > this thread was to implement the policy: "if a document starts with a
                          > > lot of blanks followed by one of the possible LaTeX sectioning
                          > > commands, then it is (probably) a LaTeX source file". What do you
                          > > think of this policy?

                          I think my undergraduate thesis (1985, plain TeX, just about the
                          time the first version of LaTeX came out) was structured that way (i.e.,
                          split into separate files, each beginning with a \chapter command or
                          something like that. (My thesis was also my introduction to vi.)

                          I also had several collections of macros, so my TeX files usually
                          started out with

                          \magnification 1200
                          \input standard
                          \input math
                          \input smiley

                          or something like that. I do not recall whether I defined any
                          sectioning commands in these files.

                          Now that you describe your proposed policy more, I like it a little
                          better. Specifically, I like the idea of looking at the first
                          non-comment, non-blank line, since that gets around the problem that
                          something that *looks* like LaTeX might be defined in an \input file. I
                          would like it better if it were more conservative. The problem is that
                          the LaTeX sectioning commands are not very LaTeX-y: if you were looking
                          for

                          \begin{chapter}

                          instead of

                          \chapter

                          then I would be a lot happier.

                          > I actually like this policy a lot. Most people who break latex files up
                          > into tonnes and tonnes of little files, do so based on sections. Odds
                          > are, that the little files will begin with a bunch of comments, and a
                          > sectioning command.
                          >
                          > It would make life easier if this made it into filetype.vim. Especially
                          > because changing g:tex_flavor means that every time I edit a plain tex
                          > file, I need to unlet this variable.

                          Another option is to add one of the lines

                          %&plain
                          %&tex
                          %&pdfplain

                          or

                          %&pdftex

                          at the top of the plain TeX files (assuming that they are your own).
                          This is the most reliable method for determining file the TeX flavor,
                          since it overrides a format specified on the command line:

                          $ latex myfile

                          will *not* load the LaTeX format if myfile.tex starts with one of the
                          above lines. The only problem (unless this has changed since the last
                          time I checked) is that the pdftex program is not smart enough to change
                          %&plain to %&pdfplain .

                          For now, I suggest doing what you think is right in the Debian
                          package. If plain TeX is really as rare as you think (I do not
                          disagree, but I am willing to be surprised!) and there are no
                          complaints, then I might vote for a change to the vim distro based on
                          feedback from Debian users.

                          HTH --Benji Fisher
                        Your message has been successfully submitted and would be delivered to recipients shortly.