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
LaTeX: add styling to general index, similar to domain indices #5583
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -1623,8 +1623,11 @@ | |||
|
||||
% additional customizable styling | ||||
\def\sphinxstyleindexentry #1{\texttt{#1}} | ||||
\def\sphinxstyleindexextra #1{ \emph{(#1)}} | ||||
\def\sphinxstyleindexextra #1{ (\emph{#1})} | ||||
\def\sphinxstyleindexpageref #1{, \pageref{#1}} | ||||
\def\sphinxstyleindexpagemain#1{\textbf{#1}} | ||||
\protected\def\spxentry#1{#1}% will get \let to \sphinxstyleindexentry in index | ||||
\protected\def\spxextra#1{#1}% will get \let to \sphinxstyleindexextra in index | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I decided to re-use the same sphinx/sphinx/writers/latex.py Line 784 in 8b687ac
An alternative would be to define independent macros The On the xindy side I looked a bit about using
but did not see a way to add there the |
||||
\def\sphinxstyleindexlettergroup #1% | ||||
{{\Large\sffamily#1}\nopagebreak\vspace{1mm}} | ||||
\def\sphinxstyleindexlettergroupDefault #1% | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,12 @@ | |
;; Unfortunately xindy is out-of-the-box hyperref-incompatible. This | ||
;; configuration is a workaround, which requires to pass option | ||
;; hyperindex=false to hyperref. | ||
;; textit and emph not currently used by Sphinx LaTeX writer. | ||
(define-attributes (("textbf" "textit" "emph" "default"))) | ||
;; textit and emph not currently used, spxpagem replaces former textbf | ||
(define-attributes (("textbf" "textit" "emph" "spxpagem" "default"))) | ||
(markup-locref :open "\textbf{\hyperpage{" :close "}}" :attr "textbf") | ||
(markup-locref :open "\textit{\hyperpage{" :close "}}" :attr "textit") | ||
(markup-locref :open "\emph{\hyperpage{" :close "}}" :attr "emph") | ||
(markup-locref :open "\spxpagem{\hyperpage{" :close "}}" :attr "spxpagem") | ||
(markup-locref :open "\hyperpage{" :close "}" :attr "default") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Initially I had also added a In the end I dropped this: it is always possible if wanted to style the index page number at LaTeX macro level by modifying |
||
|
||
(require "numeric-sort.xdy") | ||
|
@@ -193,6 +194,9 @@ | |
(markup-index :open "\begin{sphinxtheindex} | ||
\let\lettergroup\sphinxstyleindexlettergroup | ||
\let\lettergroupDefault\sphinxstyleindexlettergroupDefault | ||
\let\spxpagem\sphinxstyleindexpagemain | ||
\let\spxentry\sphinxstyleindexentry | ||
\let\spxextra\sphinxstyleindexextra | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regarding I also hesitated about moving these |
||
|
||
" | ||
:close " | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -169,6 +169,8 @@ | |||||||||||
}, | ||||||||||||
} # type: Dict[unicode, Dict[unicode, unicode]] | ||||||||||||
|
||||||||||||
EXTRA_RE = re.compile(r'^(.*\S)\s+\(([^()]*)\)\s*$') | ||||||||||||
|
||||||||||||
|
||||||||||||
class collected_footnote(nodes.footnote): | ||||||||||||
"""Footnotes that are collected are assigned this class.""" | ||||||||||||
|
@@ -1884,8 +1886,8 @@ def depart_attribution(self, node): | |||||||||||
# type: (nodes.Node) -> None | ||||||||||||
self.body.append('\n\\end{flushright}\n') | ||||||||||||
|
||||||||||||
def visit_index(self, node, scre=re.compile(r';\s*')): | ||||||||||||
# type: (nodes.Node, Pattern) -> None | ||||||||||||
def visit_index(self, node, scre = None): | ||||||||||||
# type: (nodes.Node, None) -> None | ||||||||||||
def escape(value): | ||||||||||||
value = self.encode(value) | ||||||||||||
value = value.replace(r'\{', r'\sphinxleftcurlybrace{}') | ||||||||||||
|
@@ -1895,33 +1897,57 @@ def escape(value): | |||||||||||
value = value.replace('!', '"!') | ||||||||||||
return value | ||||||||||||
|
||||||||||||
def style(string): | ||||||||||||
match = EXTRA_RE.match(string) | ||||||||||||
if match: | ||||||||||||
return match.expand(r'\\spxentry{\1}\\spxextra{\2}') | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This mark-up is modeled on sphinx/sphinx/writers/latex.py Lines 800 to 804 in 8b687ac
which applies to entries for domain indices. But here the "extra" is recovered from this input syntax:
|
||||||||||||
else: | ||||||||||||
return '\\spxentry{%s}' % string | ||||||||||||
|
||||||||||||
if scre: | ||||||||||||
warnings.warn(('LaTeXTranslator.visit_index() optional argument ' | ||||||||||||
'"scre" is deprecated. It is ignored.'), | ||||||||||||
RemovedInSphinx30Warning, stacklevel=2) | ||||||||||||
if not node.get('inline', True): | ||||||||||||
self.body.append('\n') | ||||||||||||
entries = node['entries'] | ||||||||||||
for type, string, tid, ismain, key_ in entries: | ||||||||||||
m = '' | ||||||||||||
if ismain: | ||||||||||||
m = '|textbf' | ||||||||||||
m = '|spxpagem' | ||||||||||||
try: | ||||||||||||
if type == 'single': | ||||||||||||
p = scre.sub('!', escape(string)) | ||||||||||||
self.body.append(r'\index{%s%s}' % (p, m)) | ||||||||||||
try: | ||||||||||||
p1, p2 = [escape(x) for x in split_into(2, 'single', string)] | ||||||||||||
P1, P2 = style(p1), style(p2) | ||||||||||||
self.body.append(r'\index{%s@%s!%s@%s%s}' % (p1, P1, p2, P2, m)) | ||||||||||||
except ValueError: | ||||||||||||
p = escape(split_into(1, 'single', string)[0]) | ||||||||||||
P = style(p) | ||||||||||||
self.body.append(r'\index{%s@%s%s}' % (p, P, m)) | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also fixes #5576. |
||||||||||||
elif type == 'pair': | ||||||||||||
p1, p2 = [escape(x) for x in split_into(2, 'pair', string)] | ||||||||||||
self.body.append(r'\index{%s!%s%s}\index{%s!%s%s}' % | ||||||||||||
(p1, p2, m, p2, p1, m)) | ||||||||||||
P1, P2 = style(p1), style(p2) | ||||||||||||
self.body.append(r'\index{%s@%s!%s@%s%s}\index{%s@%s!%s@%s%s}' % | ||||||||||||
(p1, P1, p2, P2, m, p2, P2, p1, P1, m)) | ||||||||||||
elif type == 'triple': | ||||||||||||
p1, p2, p3 = [escape(x) for x in split_into(3, 'triple', string)] | ||||||||||||
P1, P2, P3 = style(p1), style(p2), style(p3) | ||||||||||||
self.body.append( | ||||||||||||
r'\index{%s!%s %s%s}\index{%s!%s, %s%s}' | ||||||||||||
r'\index{%s!%s %s%s}' % | ||||||||||||
(p1, p2, p3, m, p2, p3, p1, m, p3, p1, p2, m)) | ||||||||||||
r'\index{%s@%s!%s %s@%s %s%s}' | ||||||||||||
r'\index{%s@%s!%s, %s@%s, %s%s}' | ||||||||||||
r'\index{%s@%s!%s %s@%s %s%s}' % | ||||||||||||
(p1, P1, p2, p3, P2, P3, m, | ||||||||||||
p2, P2, p3, p1, P3, P1, m, | ||||||||||||
p3, P3, p1, p2, P1, P2, m)) | ||||||||||||
elif type == 'see': | ||||||||||||
p1, p2 = [escape(x) for x in split_into(2, 'see', string)] | ||||||||||||
self.body.append(r'\index{%s|see{%s}}' % (p1, p2)) | ||||||||||||
P1 = style(p1) | ||||||||||||
self.body.append(r'\index{%s@%s|see{%s}}' % (p1, P1, p2)) | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did not make any attempt into adding mark-up in the |
||||||||||||
elif type == 'seealso': | ||||||||||||
p1, p2 = [escape(x) for x in split_into(2, 'seealso', string)] | ||||||||||||
self.body.append(r'\index{%s|see{%s}}' % (p1, p2)) | ||||||||||||
P1 = style(p1) | ||||||||||||
self.body.append(r'\index{%s@%s|see{%s}}' % (p1, P1, p2)) | ||||||||||||
else: | ||||||||||||
logger.warning(__('unknown index entry type %s found'), type) | ||||||||||||
except ValueError as err: | ||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved the parentheses outside the scope of
\emph
. imho, it looks better this way.