# Pretty Printing Parentheses [closed]

The worst part about long lines or code or math equations are the parentheses. Nobody wants to read through 2x(3y+4*abs(x^[2*e^x])-5{3(x+y)-5})!

So, the goal of this challenge is to make it at least slightly easier to read these parentheses-filled beasts! For the above math equation, the output should be:

2x (
3y+4*abs (
x^ [
2*e^x
]
)
-5 {
3 (
x+y
)
-5
}
)


A parenthesis is defined as either of these characters: ()[]{}. Indents should each be two spaces, and there should be one space of seperation between the expression and the parenthesis: 2x (, x^ [ as some examples.

I would like to debut the Atomic Code Golf metric in this question. Take out all separators in your code (()[]{}. ; to name some common ones), and then take the length of your program if every reserved word and operator were 1 character long. That is your program's score. if x**(3.2)==b[3]:print x is 11 points: if|x|**|3|.|2|==|b|3|print|x, or ix*3.2=b3px. Any quick questions about the metric can be posted here; larger questions should be discussed in meta using the link above.

Lowest score wins. Good luck, have fun!

• Is $x one token or two? – mob Commented Feb 21, 2013 at 3:59 • @mob: Depends on what $x is: if it's a variable, 1 token. If it's a math operator, then 2. Commented Feb 21, 2013 at 4:14
• I've voted to close this as unclear as the challenge body does not properly specify what counts as a "separator" Commented Mar 27, 2021 at 4:16
• Was this sandboxed? There are plenty of languages that can easily write programs consisting of only characters on your "common separator" list. Commented Mar 27, 2021 at 6:59
• @WheatWizard This was asked in 2013, so I think it's unlikely it was sandboxed (given that sandboxes really started in 2014) Commented Mar 27, 2021 at 22:51

## C, 139 137 chars, 67 tokens

i,n;                                                      // 2 tokens
main(c){                                                  // 2 tokens
while(~(c=getchar()))                             // 5 tokens
n=strchr("([{}])",c)?                     // 11 tokens
n=c%4!=1,                         // 7 tokens
i+=n*4-2,                         // 7 tokens
printf("\n%*s%c"+n,n?1:i,"",c)    // 15 tokens
:                                         // 1 token
$y"!ge;s/ * / /g;print  # JavaScript (V8), 76 74 (a,d)=>(d=0)||a.replaceAll(/[(${]/g,b=> {b}\n+' '.repeat(++d)).replaceAll(/[)$}]/g,b=>\n${(f='  '.repeat(--d))+b}\n${f})  Try it online! (a,d)=> pas argument a and d (a is the string, d is just as decleration) (d=0)|| set d to 0 a.replaceAll( replace everything in a that matches.... /[(${]/g, [,(,{ with.... b=> pass matches into function  {b}\n space, bracket(the match) and newline +' '.repeat(++d) increment d and repeat the 2 spaces d times ) .replaceAll(/[)$}]/g, match all ),],} and replace them with.... b=> pass matches into function \n${(f='  '.repeat(--d))+b}\n${f} newline, decrement d and repeat the 2 spaces d times, closing bracket(the match), newline and once again the repeated spaces )  results in #a#,#d#=>#d#=#0#||#a#replaceAll#/#[#(#\#[#{#]#/#g#b#=>## #$#{#b#}#\#n##+#'# # #'#repeat#++#d#replaceAll#/#[#)#\#]#}#]#/#g#b#=>##\#n#$#{#f#=#'# # #'#r#e#p#e#a#t#--#d#+#b#}#\#n#$#{#f#}##

• You can probably remove the braces {} inside the backticks
– Wezl
Commented Mar 26, 2021 at 22:48
• @Wezl , i am not so sure about those, as he specified only sperators, not sure if these are sperators. Commented Mar 26, 2021 at 22:54