### Install md2tgmd using pip Source: https://github.com/yym68686/md2tgmd/blob/main/README.md This command installs the md2tgmd library using pip, making it available for use in Python projects. Ensure you have pip installed and configured correctly. ```bash pip install md2tgmd ``` -------------------------------- ### Supported LaTeX Symbols and Operators Source: https://context7.com/yym68686/md2tgmd/llms.txt Examples of various LaTeX symbol categories supported by the library, including set operations, arrows, logic, and calculus symbols. ```python from latex2unicode import LaTeX2Unicode l2u = LaTeX2Unicode() # Set operations print(l2u.convert("A \\subset B \\cup C \\cap D \\in E \\notin F")) # Logic and relations print(l2u.convert("\\forall x \\exists y \\neg P \\wedge Q \\vee R")) # Calculus print(l2u.convert("\\int \\partial \\nabla \\infty \\sum \\prod")) ``` -------------------------------- ### Integrate Markdown Formatting for Telegram Bots Source: https://context7.com/yym68686/md2tgmd/llms.txt A comprehensive example showing how to escape markdown text and handle message splitting before sending via the Telegram Bot API. ```python from md2tgmd import escape def format_message_for_telegram(markdown_text): formatted = escape(markdown_text) if "@|@|@|@" in formatted: return formatted.split("@|@|@|@") return [formatted] # Usage with math content response = "# Euler's Totient Function\n\\( \\varphi(35) = 24 \\)" messages = format_message_for_telegram(response) for msg in messages: print(msg) ``` -------------------------------- ### Convert LaTeX to Unicode with md2tgmd Source: https://context7.com/yym68686/md2tgmd/llms.txt Demonstrates the use of the l2u module to convert LaTeX mathematical notation into readable Unicode characters. ```python from md2tgmd import l2u comparison = l2u.convert("x \\leq y \\geq z \\neq w \\approx v") print(comparison) # Output: x ≤ y ≥ z ≠ w ≈ v ``` -------------------------------- ### Convert Markdown to Telegram Format Source: https://context7.com/yym68686/md2tgmd/llms.txt Demonstrates the primary escape function to convert Markdown text into Telegram-compatible syntax, including headings, lists, links, and code blocks. ```python from md2tgmd import escape text = ''' # Welcome to My Bot This is **bold** and _italic_ text with ~~strikethrough~~. ## Math Example The formula \( \alpha + \beta = \gamma \) demonstrates inline math. \[ \varphi(35) = 35 \left(1 - \frac{1}{5}\right) \left(1 - \frac{1}{7}\right) \] ## Code Example ```python def hello(): print("Hello, World!") ``` ''' result = escape(text) print(result) ``` -------------------------------- ### Configure Italic Formatting in escape Source: https://context7.com/yym68686/md2tgmd/llms.txt Shows how to use the optional italic parameter to toggle whether underscores are treated as italic markers or escaped as literal characters. ```python from md2tgmd import escape # With italic enabled (default) text_with_italic = "This is _italic_ text and some_variable_name" result_italic = escape(text_with_italic, italic=True) print(result_italic) # With italic disabled text_no_italic = "Use some_function_name() in your code" result_no_italic = escape(text_no_italic, italic=False) print(result_no_italic) ``` -------------------------------- ### Convert Markdown to Telegram Markdown with md2tgmd Source: https://github.com/yym68686/md2tgmd/blob/main/README.md This Python code snippet demonstrates how to use the `escape` function from the `md2tgmd` library to convert a given Markdown string into a format compatible with Telegram's markdown. It showcases the conversion of various Markdown elements including headings, bold text, code blocks, links, images, lists, and LaTeX formulas. ```python from md2tgmd import escape text = ''' # Title \[ \varphi(35) = 35 \left(1 - \frac{1}{5}\right) \left(1 - \frac{1}{7}\right) \] **Bold** ``` # Comment print(qwer) # ferfe ni1 ``` # bn # b # Title ## Subtitle [1.0.0](http://version.com) ![1.0.0](http://version.com) - Item 1 - - Item 1 - - Item 1 - * Item 2 # * Item 3 ~ 1. Item 1 2. Item 2 sudo apt install mesa-utils # Install ```python # Comment print("1.1\n")_ \subsubsection{1.1} ``` \subsubsection{1.1} And simple text `with-ten` `with+ten` + some - **symbols**. # `-` inside `with-ten` will not be escaped ``` print("Hello, World!") - ``` Cxy = abs (Pxy)**2/ (Pxx*Pyy) `a`a-b-c`n` `-a----++++`++a-b-c`-n-` `[^``]*`a``b-c``d`` # pattern = r"`[^`]*`-([^`-]*)`` w`-a----`ccccc`-n-`bbbb``a ''' print(escape(text)) ``` -------------------------------- ### Perform Pattern-Based Text Replacement Source: https://context7.com/yym68686/md2tgmd/llms.txt Uses the replace_all function to apply custom transformations to specific regex patterns within a string, useful for markdown processing. ```python from md2tgmd import replace_all # Apply transformation to bold markers text = "This is **important** information" result = replace_all(text, r"(\\*\\*.*?\\*\\*)", lambda x: x.replace("**", "").upper()) print(result) # Escape parentheses inside code blocks def escape_code(code): return code.replace("(", "\\(").replace(")", "\\)") text_with_code = "Run `print(hello)` in Python" result = replace_all(text_with_code, r"(`[^`]+`)", escape_code) print(result) ``` -------------------------------- ### Convert LaTeX to Unicode Characters Source: https://context7.com/yym68686/md2tgmd/llms.txt Utilizes the LaTeX2Unicode class to convert mathematical notation, fractions, and symbols into Unicode representations independent of Markdown processing. ```python from latex2unicode import LaTeX2Unicode l2u = LaTeX2Unicode() # Greek letters print(l2u.convert("\\alpha + \\beta = \\gamma")) # Fractions print(l2u.convert("\\frac{1}{2} + \\frac{3}{4}")) # Subscripts and superscripts print(l2u.convert("x^{2} + y_{1}")) ``` -------------------------------- ### Split Long Code Blocks for Telegram Source: https://context7.com/yym68686/md2tgmd/llms.txt The split_code function automatically detects code blocks exceeding Telegram's character limits and inserts markers to facilitate splitting. ```python from md2tgmd import split_code long_code = '```python\ndef function1(): pass\n...\n```' result = split_code(long_code) short_code = '```python\nprint("Hello")\n```' result = split_code(short_code) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.