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

new TeX mode (again) #625

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions manual/aspell.1
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ Check TeX comments.
\fB\-\-add\-tex\-command=\fR\fI<list>\fR, \fB\-\-rem\-tex\-command=\fR\fI<list>\fR
Add or remove a list of TeX commands.
.TP
\fB\-\-add\-tex\-ignore\-env=\fR\fI<list>\fR, \fB\-\-rem\-tex\-ignore\-env=\fR\fI<list>\fR
Add or remove a list of LaTeX environments to skip while spell checking.
.TP
\fB\-\-add\-texinfo\-ignore=\fR\fI<list>\fR, \fB\-\-rem\-texinfo\-ignore=\fR\fI<list>\fR
Add or remove a list of Texinfo commands.
.TP
Expand Down
81 changes: 76 additions & 5 deletions manual/aspell.texi
Original file line number Diff line number Diff line change
Expand Up @@ -1220,10 +1220,18 @@ The @option{tex} (all lowercase) filter hides @TeX{}/LaTeX commands and
corresponding parameters that are not readable text in the output from
Aspell. It also skips over @TeX{} comments by default.

Discretionary hyphens and italic corrections are ignored. For example,
@samp{hy\-phen} and @samp{shelf\/ful} are recognized as single words.

@c This filter mode is also available via the
@c @option{latex} alias name.

@table @b

@item tex-check-comments
@i{(boolean)}
Check @TeX{} comments. Defaults to false.

@item tex-command
@i{(list)}
Controls which @TeX{} commands should have certain parameters and/or
Expand All @@ -1232,13 +1240,15 @@ all their parameters and/or options checked. The format for each item
is

@example
<command> <a list of p,P,o and Os>
<command> <a list of 'p', 'P', 'o', 'O' and 'T's>
@end example

The first item is simply the command name. The second item controls
which parameters to skip over. A 'p' skips over a parameter while a
'P' doesn't. Similarly an 'o' will skip over an optional parameter
while an 'O' doesn't. The first letter on the list will apply to the
while an 'O' doesn't. A 'T' will force spell-checking of a parameter
even if the command occurs within a parameter or an environment Aspell
is told to skipped over. The first letter on the list will apply to the
first parameter, the second letter will apply to the second parameter
etc. If there are more parameters than letters Aspell will simply
check them as normal. For example the option
Expand All @@ -1261,6 +1271,25 @@ over the next optional parameter, if it is present, and will skip over
the second parameter --- even if the optional parameter is not present
--- and will check any additional parameters.

@example
add-tex-command foo T
@end example

@noindent
will @emph{check} the first parameter of the @code{foo} command even
if Aspell is currently skipping over an argument or environment. For
example, if Aspell has been told to skip over the @code{bar}
environment (@pxref{Ignoring LaTeX Environments}), then in the text

@example
\begin@{bar@} don't check \foo@{check@} don't check \end@{bar@}
@end example

@noindent
it will nevertheless @emph{check} the argument to @code{foo}. This is
useful to force checking of arguments to text-related commands like
@code{hbox}, @code{text} or @code{intertext} inside math environments.

A @samp{*} at the end of the command is simply ignored. For example
the option

Expand All @@ -1287,15 +1316,56 @@ current defaults.
@c will remove the command foo, if present, from the list of @TeX{}
@c commands.

@item tex-check-comments
@i{(boolean)}
Check @TeX{} comments. Defaults to false.
@anchor{Ignoring LaTeX Environments}
@item tex-ignore-env
@i{(list)}
This controls which @TeX{} environments are skipped over. By default,
Aspell will skip over math formulas inside @code{$...$}, @code{$$...$$},
@code{\(...\)} and @code{\[...\]} and over several common LaTeX and
AMS-LaTeX math environments like @code{equation} and @code{gather}.
For example,

@example
add-tex-ignore-env thebibliography
@end example

@noindent
will tell Aspell to skip over the bibliography as well (which may or
may not be a good idea). As with commands, skipping applies to the
starred form of the environment as well.

@example
rem-tex-ignore-env equation
@end example

@noindent
will make Aspell spell-check the contents of @code{equation} and
@code{equation*} environments. Skipping the contents of @code{$...$},
@code{$$...$$}, @code{\(...\)} and @code{\[...\]} cannot be turned off.

Note that one can force spell-checking of arguments to TeX commands
inside ignored environments with the 'T' parameter to the
@option{add-tex-command} option.

@c @item tex-multi-byte
@c (@i{list}) TeX multi byte letter en|decoding

@end table

As a last resort, spell checking can be switched off by putting the
text @code{aspell:off} into the file. Similarly, with @code{aspell:on}
one can turn it on again. This can be useful for macro definitions,
for example

@example
% aspell:off
\def\doi#1@{\href@{http://doi.org/#1@}@{doi:#1@}@}
% aspell:on
@end example

@noindent
This feature is implemented via the @ref{Context Filter}.

@c The TeXfilter mode also contains a decoding and an encoding filter for
@c @emph{babel} character codes like the German Umlauts:

Expand Down Expand Up @@ -1404,6 +1474,7 @@ escapes
(@code{\(}) and extended (@code{\[comp1 comp2 @dots{}]}) form.
@end itemize

@anchor{Context Filter}
@subsubsection Context Filter

The @option{context} filter can be used to spell check source codes,
Expand Down
1 change: 1 addition & 0 deletions modules/filter/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ namespace {

PosibErr<bool> ContextFilter::setup(Config * config){
name_ = "context-filter";
order_num_ = 0.15;
Copy link
Member

Choose a reason for hiding this comment

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

Changing the order number is likely to break something. If it needs to be changed than it should be an option to the context filer, something like "order-num <float>" where float is a number between 0 and 1.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At present, order_num is not defined at all for the context filter. What does that mean? Is the filter applied first, last or somewhere else? (If I knew the answer 12 years ago when I wrote this patch, I've forgotten it in the meantime.)

Copy link
Member

Choose a reason for hiding this comment

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

It defaults to 0.50:

IndividualFilter() : name_(0), order_num_(0.50) {}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kevina I understand your concern that this may break something. For the new TeX mode, however, it is important that the context filter comes first. So it would have to be added as an option. Unfortunately, my familiarity with the aspell code is (and never was) sufficient to add such an option. Would you be willing to help out?

Copy link
Member

Choose a reason for hiding this comment

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

Yes. It shouldn't be too hard to modify the context filter to add the option.

StringList delimiters;
StackPtr<StringEnumeration> delimiterpairs;
const char * delimiterpair=NULL;
Expand Down
5 changes: 4 additions & 1 deletion modules/filter/modes/tex.amf
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,8 @@ MAGIC /0:256:^[ \t]*\\documentclass\[[^\[\]]*\]\{[^\{\}]*\}/tex

DESCRIPTION mode for checking TeX/LaTeX documents

FILTER url
matthias314 marked this conversation as resolved.
Show resolved Hide resolved
FILTER context
OPTION clear-context-delimiters
OPTION add-context-delimiters aspell:off aspell:on
OPTION enable-context-visible-first
FILTER tex
56 changes: 48 additions & 8 deletions modules/filter/tex-filter.info
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,35 @@ DESCRIPTION check TeX comments
DEFAULT false
ENDOPTION

OPTION ignore-env
TYPE list
DESCRIPTION LaTeX environments to be ignored
# LaTeX
#DEFAULT thebibliography
DEFAULT equation
DEFAULT eqnarray
# AMS-LaTeX
DEFAULT gather
DEFAULT multline
DEFAULT align
DEFAULT flalign
DEFAULT alignat
# Babel
DEFAULT otherlanguage
ENDOPTION

OPTION command
TYPE list
DESCRIPTION TeX commands
# plain TeX / LaTeX
DEFAULT addtocounter pp
DEFAULT addtolength pp
DEFAULT alpha p
DEFAULT alph p
DEFAULT Alph p
DEFAULT arabic p
DEFAULT fnsymbol p
DEFAULT roman p
DEFAULT Roman p
DEFAULT stepcounter p
DEFAULT setcounter pp
DEFAULT usecounter p
Expand All @@ -42,7 +62,8 @@ DEFAULT newtheorem poPo
DEFAULT newfont pp
DEFAULT documentclass op
DEFAULT usepackage op
DEFAULT begin po
# DO NOT change the next line!
DEFAULT begin so
DEFAULT end p
DEFAULT setlength pp
DEFAULT addtolength pp
Expand All @@ -54,15 +75,17 @@ DEFAULT hyphenation p
DEFAULT pagenumbering p
DEFAULT pagestyle p
DEFAULT addvspace p
DEFAULT framebox ooP
DEFAULT framebox ooT
DEFAULT hspace p
DEFAULT vspace p
DEFAULT makebox ooP
DEFAULT parbox ooopP
DEFAULT raisebox pooP
DEFAULT hbox T
DEFAULT vbox T
DEFAULT makebox ooT
DEFAULT parbox ooopT
DEFAULT raisebox pooT
DEFAULT rule opp
DEFAULT sbox pO
DEFAULT savebox pooP
DEFAULT savebox pooT
DEFAULT usebox p
DEFAULT include p
DEFAULT includeonly p
Expand All @@ -76,13 +99,30 @@ DEFAULT fontshape p
DEFAULT fontsize pp
DEFAULT usefont pppp
DEFAULT documentstyle op
DEFAULT cite p
DEFAULT cite Op
DEFAULT nocite p
DEFAULT psfig p
DEFAULT selectlanguage p
DEFAULT includegraphics op
DEFAULT bibitem op
DEFAULT bibliography p
DEFAULT bibliographystyle p
DEFAULT geometry p
# AMS-LaTeX
DEFAULT address p
DEFAULT email p
DEFAULT mathbb p
DEFAULT mathfrak p
DEFAULT eqref p
DEFAULT text T
DEFAULT intertext T
DEFAULT DeclareMathOperator pp
DEFAULT DeclareMathAlphabet ppppp
# hyperref
DEFAULT href pP
DEFAULT autoref p
DEFAULT url p
DEFAULT texorpdfstring Pp
ENDOPTION

#OPTION multi-byte
Expand Down
Loading