Skip to content

Commit

Permalink
more correct emulation of parameter tokens for \index
Browse files Browse the repository at this point in the history
  • Loading branch information
dginev committed Nov 17, 2023
1 parent ee2f9a5 commit 82052e7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 22 deletions.
23 changes: 4 additions & 19 deletions lib/LaTeXML/Package/LaTeX.pool.ltxml
Original file line number Diff line number Diff line change
Expand Up @@ -4421,15 +4421,7 @@ sub process_index_phrases {
my @tokens = $phrases->unlist;
# check we have a well-formed argument
return unless @tokens;
my $group_level = 0;
for my $t (@tokens) {
my $cc = $t->getCatcode;
if ($cc == CC_BEGIN) { $group_level++; }
elsif ($cc == CC_END) {
$group_level--;
# discard if unbalanced close group;
last if ($group_level < 0); } }
if ($group_level != 0) { # if a group is still open by the end, ill-formed, discard;
if (!$phrases->isBalanced) { # if ill-formed, discard;
Warn("malformed", "indexentry", $gullet,
'index entry has unbalanced groups, discarding: "' . ToString($phrases) . '"');
return; }
Expand Down Expand Up @@ -4480,28 +4472,21 @@ DefParameterType('SanitizedVerbatim', sub {
# chars switched to CC_OTHER by \@sanitize: ' ', '\\', '$', '&', '#', '^', '_', '%', '~'
# some of those are already in state's "SPECIALS", so only adding the rest:
StartSemiverbatim(' ', '\\', '%');
my $arg = $gullet->readBalanced(1);
my $arg = $gullet->readBalanced();
EndSemiverbatim();
# now that we have the semiverbatim tokens, retokenize with the standard catcode scheme,
# now that we have the semiverbatim tokens, retokenize.
# this may seem like wasted work, but it avoids very unfortunate error propagation in cases
# where the \index argument was malformed for one reason or another.
#
# the strangeness comes from the original TeX workflow requiring multiple conversion calls,
# alongside a call to the `makeidx` binary, which we don't do in latexml. This parameter type
# emulates one important aspect implied by those steps.
$arg = Tokenize(ToString($arg));
$arg = TokenizeInternal(UnTeX($arg));
return $arg; },
beforeDigest => sub {
$_[0]->bgroup;
MergeFont(family => 'typewriter'); },
afterDigest => sub {
$_[0]->egroup; },
reversion => sub { (T_BEGIN, Revert($_[0]), T_END); });

# real-world LaTeX \index
DefMacro('\index SanitizedVerbatim', \&process_index_phrases);
# simple \index for internal use in bindings with pre-sanitized arguments
DefMacro('\lx@simple@index Plain', \&process_index_phrases);

Tag('ltx:indexphrase', afterClose => \&addIndexPhraseKey);
Tag('ltx:glossaryphrase', afterClose => \&addIndexPhraseKey);
Expand Down
4 changes: 1 addition & 3 deletions lib/LaTeXML/Package/listings.sty.ltxml
Original file line number Diff line number Diff line change
Expand Up @@ -1019,9 +1019,7 @@ DefKeyVal('LST', 'indexstyle', '');
DefMacro('\lst@@indexstyle [Number] Until:\end', sub {
lstSetClassStyle(lstClassName('index', $_[1]), $_[2]); });

# use the simple plain-argument index,
# otherwise we need to double-check any relevant Semiverbatim cases
DefMacro('\lstindexmacro{}', '\lx@simple@index{{\ttfamily #1}}');
DefMacro('\lstindexmacro{}', '\index{{\ttfamily #1}}');

#======================================================================
# 4.13 Column alignment
Expand Down

0 comments on commit 82052e7

Please sign in to comment.