Color | RGB | Item | RGB |
---|---|---|---|
Black |
|
Foreground |
|
Red |
|
Background |
|
Green |
|
Cursor color |
|
Yellow |
|
Selection background |
|
Blue |
|
||
Purple |
|
||
Cyan |
|
||
White |
|
Note: Colors are displayed using LaTeX format
Color | RGB | Item | RGB |
---|---|---|---|
Black |
|
Foreground |
|
Red |
|
Background |
|
Green |
|
Cursor color |
|
Yellow |
|
Selection background |
|
Blue |
|
||
Purple |
|
||
Cyan |
|
||
White |
|
Note: Colors are displayed using LaTeX format
def hex_to_latex(hex_color, text="Color"): | |
# Ensure the hex code starts with '#' | |
if hex_color.startswith('#'): | |
hex_color = hex_color[1:] | |
# Convert hex to RGB (0-255) | |
r, g, b = tuple(int(hex_color[i:i+2], 16) for i in (0, 2, 4)) | |
# Normalize to (0-1) range for LaTeX | |
r_norm, g_norm, b_norm = r / 255, g / 255, b / 255 | |
# Format LaTeX command | |
latex_command = f"{{\\textsf{{\\textcolor[rgb]{{{r_norm:.3f}, {g_norm:.3f}, {b_norm:.3f}}}{{{text}}}}}}}" | |
return latex_command | |
# Example usage | |
hex_code = "#300A24" | |
print(hex_to_latex(hex_code, "■")) # Outputs: {\textsf{\textcolor[rgb]{0.188, 0.039, 0.141}{■}}} |
def hex_to_latex(hex_color, text="Color"): | |
# Ensure the hex code starts with '#' | |
if hex_color.startswith('#'): | |
hex_color = hex_color[1:] | |
# Convert hex to RGB (0-255) | |
r, g, b = tuple(int(hex_color[i:i+2], 16) for i in (0, 2, 4)) | |
# Format LaTeX command with RGB (0-255) | |
latex_command = f"{{\\textsf{{\\textcolor[RGB]{{{r}, {g}, {b}}}{{{text}}}}}}}" | |
return latex_command | |
# Example usage | |
hex_code = "#300A24" | |
print(hex_to_latex(hex_code, "■")) # Output: {\textsf{\textcolor[RGB]{48, 10, 36}{■}}} |