10
$\begingroup$

I drew the little ASCII-art electronics schema below in vim.

When i try to paste it into a Mathematica notebook, with:

A) A code cell
B) A monospaced font (Courier New)

Mathematica insists on destroying the vertical aligment.

Here is what it looks like in vim: enter image description here

And here's what it looks like in Mathematica:

enter image description here

Even worse, when I try to re-align things by hand in the notebook, the end result looks very bad (note the misaligned vertical bars on the right hand side)

enter image description here

For something so simple to be so hard ... I must be missing something glaringly obvious.

Help would be very much appreciated.

$\endgroup$
11
  • 2
    $\begingroup$ Why are you pasting text into a code cell? Code cells automatically format their contents. You'll never get it to look right. Perhaps you want to Import the file as a String? $\endgroup$
    – Michael E2
    Commented Nov 30, 2013 at 19:23
  • 1
    $\begingroup$ Mathematica notebook really needs a verbatim cell and/or verbatim wrapper, where one can write Verbatim[" string "] and the content will show as is. No formating. As in Latex's verbatim environment ctan.org/pkg/verbatim, can be used for comments in code as well. Try making free form comments using (* *) and you'll see how hard it is to align the comments the way you want with the code. $\endgroup$
    – Nasser
    Commented Nov 30, 2013 at 19:58
  • $\begingroup$ As a side note, if you're interested more in drawing circuits than text alignment, you might find these useful: Circuit drawing in Mathematica and Graph layout on a grid $\endgroup$
    – Michael E2
    Commented Nov 30, 2013 at 20:03
  • 2
    $\begingroup$ It works for me on my own example. But it's cool you found a solution. You should post it as answer to your own question, by the way. $\endgroup$
    – Michael E2
    Commented Nov 30, 2013 at 20:28
  • 1
    $\begingroup$ Are you really pasting that into a Code cell or an Input cell? Code cells don't reformat the text, only Input cells do. Try pasting into an actual Code cell. Use Window -> Show Toolbar, select the cell bracket, change the cell style to "Code". Or insert a new cell using Alt-8 (Command-8 on Mac). $\endgroup$
    – Szabolcs
    Commented Dec 1, 2013 at 4:29

2 Answers 2

12
$\begingroup$

The Program style is purpose-built for this sort of thing:

cell using program style

If you do not like the look of the bars above and below the cell, you can remove them by selecting the cell and changing the CellFrame option in the Option Inspector:

cell with bars removed

$\endgroup$
3
$\begingroup$

I seem to have found a solution, kind of convoluted, and not entirely sure why it works.

  • Create a cell
  • Cell -> Convert To -> Raw Input Form
  • Open a comment in the cell
  • Paste the ASCII art
  • Close comment

This is what it looks like now:

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.