Skip to content
Open
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
23 changes: 23 additions & 0 deletions pandoc/beamer_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,20 @@ def latex_animate(text):
return "\\onslide<2->{" + text + "}"


"""
latex_colorize will take a color and apply it to text.
This is used by the "color-*" role, and uses the LaTeX "xcolor" package.
For now, color should be assumed to be any string that xcolor allows, but
it's only been tested with the predefined color names:
black, blue, brown, cyan, darkgray, gray, green, lightgray, lime, magenta,
olive, orange, pink, purple, red, teal, violet, white, yellow
"""


def latex_colorize(color, text):
return latex_inline("\\textcolor{" + color + "}{" + latex_escape(text) + "}")


#############################
## PANDOC HELPER FUNCTIONS ##
#############################
Expand Down Expand Up @@ -683,6 +697,15 @@ def pandoc_format(function_name, ast_string_node):

def perform_role(role, literal_text, format):
function_name = role_format_functions.get(role, None)

# This allows us to define roles for color on the fly,
# just by prefixing the color we want with "color-".
# So to write "This is a red word" where 'red' is actually
# red you would write:
# This is a :color-red:`red` word
if role.startswith("color-"):
return latex_colorize(role[6:], literal_text)

if function_name == None:
return function_name
elif function_name in dir(pandocfilters):
Expand Down
Loading