shouldnt break anything; prespecify hue in all the coloriztion commands; defaults to generator if None
@@ -111,7 +111,7 @@ class CitationColorizationBatch(NamedTuple):
colorized_citations: List[ColorizedCitation]
-def colorize_citations(tex: str) -> Iterator[CitationColorizationBatch]:
+def colorize_citations(tex: str, hue: float = None) -> Iterator[CitationColorizationBatch]:
citation_extractor = CitationExtractor()
tex = _disable_hyperref_coloring(tex)
@@ -130,6 +130,7 @@ def colorize_citations(tex: str) -> Iterator[CitationColorizationBatch]:
colorized_tex = tex
for c in citations_reverse_order:
try:
+ if hue is None:
hue = next(hue_generator)
except StopIteration:
# When the hues run out, notify caller that a batch has been finished.
@@ -145,6 +146,7 @@ def colorize_citations(tex: str) -> Iterator[CitationColorizationBatch]:
hue_generator = generate_hues()
# And get the hue for the next entity.
+ if hue is None:
hue = next(hue_generator)
colorized_tex = _insert_color_in_tex(colorized_tex, hue, c.start, c.end)
@@ -226,7 +228,7 @@ class EquationColorizationBatch(NamedTuple):
colorized_equations: List[ColorizedEquation]
-def colorize_equations(tex: str) -> Iterator[EquationColorizationBatch]:
+def colorize_equations(tex: str, hue: float = None) -> Iterator[EquationColorizationBatch]:
# TODO(andrewhead): Refactor this to share code with colorize_citations.
equation_extractor = EquationExtractor()
@@ -242,12 +244,14 @@ def colorize_equations(tex: str) -> Iterator[EquationColorizationBatch]:
colorized_tex = tex
for e in equations_reverse_order:
try:
+ if hue is None:
hue = next(hue_generator)
except StopIteration:
yield EquationColorizationBatch(colorized_tex, colorized_equations)
colorized_tex = tex
colorized_equations = []
hue_generator = generate_hues()
+ if hue is None:
hue = next(hue_generator)
colorized_tex = _insert_color_in_tex(
@@ -286,7 +290,7 @@ def _get_tokens_for_equation(
def colorize_equation_tokens(
- file_contents: Dict[TexFileName, TexContents], tokens: List[TokenWithOrigin]
+ file_contents: Dict[TexFileName, TexContents], tokens: List[TokenWithOrigin], hue: float = None
) -> Iterator[TokenColorizationBatch]:
equations_by_file: Dict[TexFileName, List[Equation]] = {}
@@ -330,7 +334,7 @@ def colorize_equation_tokens(
)
if equation_tokens is not None:
colorized_tex, colorized_tokens_for_equation = _colorize_tokens_for_equation(
- colorized_tex, equation, equation_tokens, token_skip
+ colorized_tex, equation, equation_tokens, token_skip, hue
)
colorized_tokens.extend(colorized_tokens_for_equation)
@@ -358,7 +362,7 @@ class TokenEquationColorizationBatch(NamedTuple):
def _colorize_tokens_for_equation(
- tex: str, equation: Equation, tokens: List[TokenWithOrigin], skip: int = 0
+ tex: str, equation: Equation, tokens: List[TokenWithOrigin], skip: int = 0, hue: float = None
) -> TokenEquationColorizationBatch:
"""
Colorize tokens in an equation until there are no more hues.
@@ -374,6 +378,7 @@ def _colorize_tokens_for_equation(
for token in tokens_after_skip:
try:
+ if hue is None:
hue = next(hue_generator)
except StopIteration:
break
