import string


def replace_in_text(text, replacements, capitalize=True):
    """Return the text with all the replacements done.

    Parameters
    ----------

    text
      Some string.

    replacements
      A list of the form ``[("text_to_replace", "text_replacing"), ...]``.

    capitalize
      If true, then for each pair ``"text to replace"=>"text replacing"`` in
      ``replacements``, the couple ``"Text to replace"=>"Text replacing"``
      is also added (note the capitalization of the first letter).
    """
    if capitalize:
        replacements = list(replacements) + [
            (string.capwords(target), string.capwords(replacement))
            for target, replacement in replacements
        ]
    for target, replacement in replacements:
        text = text.replace(target, replacement)
    return text