title: How to replace paired square brackets with other syntax with sed?
body: <p>I want to replace all pairs of square brackets in a file, e.g., <code>[some text]</code>, with <code>\macro{some text}</code>, e.g.:</p>
  
  <pre><code>This is some [text].
  This [line] has [some more] text.
  </code></pre>
  
  <p>This becomes:</p>
  
  <pre><code>This is some \macro{text}.
  This \macro{line} has \macro{some more} text.
  </code></pre>
  
  <ul>
  <li>The pairs only occur on individual lines, never across multiple lines.</li>
  <li>Sometimes there might be more than one pair on a single line, but they are never nested.</li>
  <li>If a bracket is found alone on a line, without a pair, then it should not be changed.</li>
  </ul>
  
  <p>How can I replace these pairs of brackets with this code?</p>