<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def remove_matching_braces(latex):
 """ If `latex` is surrounded by matching braces, remove them. They are not necessary. Parameters latex : string Returns ------- string Examples -------- '2+2' '{2+2' """

    if latex.startswith('{') and latex.endswith('}'):
        opened = 1
        matches = True
        for char in latex[1:-1]:
            if char == '{':
                opened += 1
            elif char == '}':
                opened -= 1
            if opened == 0:
                matches = False
        if matches:
            latex = latex[1:-1]
    return latex