[Question]
  [
# Challenge
Write code that outputs TeX (LaTeX) math-equation code (given below) that will typeset Sierpinski Triangle Fractal of 5 levels. **Shortest code wins**.
# Details
TeX (and friends like LaTeX, etc.) is a sophisticated typesetting system. It can render arbitrary nested complex expressions for mathematical formulas. Coincidentally this "nested complex" is also descriptive of fractals. The following is rendered with MathJaX
$${{{{{x^x\_x}^{x^x\_x}\_{x^x\_x}}^{{x^x\_x}^{x^x\_x}\_{x^x\_x}}\_{{x^x\_x}^{x^x\_x}\_{x^x\_x}}}^{{{x^x\_x}^{x^x\_x}\_{x^x\_x}}^{{x^x\_x}^{x^x\_x}\_{x^x\_x}}\_{{x^x\_x}^{x^x\_x}\_{x^x\_x}}}\_{{{x^x\_x}^{x^x\_x}\_{x^x\_x}}^{{x^x\_x}^{x^x\_x}\_{x^x\_x}}\_{{x^x\_x}^{x^x\_x}\_{x^x\_x}}}}^{{{{x^x\_x}^{x^x\_x}\_{x^x\_x}}^{{x^x\_x}^{x^x\_x}\_{x^x\_x}}\_{{x^x\_x}^{x^x\_x}\_{x^x\_x}}}^{{{x^x\_x}^{x^x\_x}\_{x^x\_x}}^{{x^x\_x}^{x^x\_x}\_{x^x\_x}}\_{{x^x\_x}^{x^x\_x}\_{x^x\_x}}}\_{{{x^x\_x}^{x^x\_x}\_{x^x\_x}}^{{x^x\_x}^{x^x\_x}\_{x^x\_x}}\_{{x^x\_x}^{x^x\_x}\_{x^x\_x}}}}\_{{{{x^x\_x}^{x^x\_x}\_{x^x\_x}}^{{x^x\_x}^{x^x\_x}\_{x^x\_x}}\_{{x^x\_x}^{x^x\_x}\_{x^x\_x}}}^{{{x^x\_x}^{x^x\_x}\_{x^x\_x}}^{{x^x\_x}^{x^x\_x}\_{x^x\_x}}\_{{x^x\_x}^{x^x\_x}\_{x^x\_x}}}\_{{{x^x\_x}^{x^x\_x}\_{x^x\_x}}^{{x^x\_x}^{x^x\_x}\_{x^x\_x}}\_{{x^x\_x}^{x^x\_x}\_{x^x\_x}}}}}$$
by the following plain-text math-equation code consisting of nested super- and sub-scripts:
```
{{{{{x^x_x}^{x^x_x}_{x^x_x}}^{{x^x_x}^{x^x_x}_{x^x_x}}_{{x^x_x}^{x^x_x}_{x^x_x}}}^{{{x^x_x}^{x^x_x}_{x^x_x}}^{{x^x_x}^{x^x_x}_{x^x_x}}_{{x^x_x}^{x^x_x}_{x^x_x}}}_{{{x^x_x}^{x^x_x}_{x^x_x}}^{{x^x_x}^{x^x_x}_{x^x_x}}_{{x^x_x}^{x^x_x}_{x^x_x}}}}^{{{{x^x_x}^{x^x_x}_{x^x_x}}^{{x^x_x}^{x^x_x}_{x^x_x}}_{{x^x_x}^{x^x_x}_{x^x_x}}}^{{{x^x_x}^{x^x_x}_{x^x_x}}^{{x^x_x}^{x^x_x}_{x^x_x}}_{{x^x_x}^{x^x_x}_{x^x_x}}}_{{{x^x_x}^{x^x_x}_{x^x_x}}^{{x^x_x}^{x^x_x}_{x^x_x}}_{{x^x_x}^{x^x_x}_{x^x_x}}}}_{{{{x^x_x}^{x^x_x}_{x^x_x}}^{{x^x_x}^{x^x_x}_{x^x_x}}_{{x^x_x}^{x^x_x}_{x^x_x}}}^{{{x^x_x}^{x^x_x}_{x^x_x}}^{{x^x_x}^{x^x_x}_{x^x_x}}_{{x^x_x}^{x^x_x}_{x^x_x}}}_{{{x^x_x}^{x^x_x}_{x^x_x}}^{{x^x_x}^{x^x_x}_{x^x_x}}_{{x^x_x}^{x^x_x}_{x^x_x}}}}}
```
Note this is just a 5-level nesting. You do not need to generate `$...$` or `$$...$$` or other markup required to start/end a math equation in TeX & Co. You can preview generated TeX in many online editors, for instance: <http://www.hostmath.com> but you can find many others too. This question was inspired by a [discussion with friends](http://community.wolfram.com/groups/-/m/t/1188472).
# Update
There is a [similar question](https://codegolf.stackexchange.com/q/138245/4997) but it much more general and will produce different solutions. I wanted to see really kolmogorov-complexity for a very fixed simple code that in one system (TeX) is completely explicit while in another compressed. This also address the `n` instead of 5 levels comment. 
  
[Answer]
# [Python 2](https://docs.python.org/2/), 32 bytes
```
exec"print'x'"+".join('{^_}')"*5
```
[Try it online!](https://tio.run/##K6gsycjPM/r/P7UiNVmpoCgzr0S9Ql1JW0kvKz8zT0O9Oi6@Vl1TScv0/38A "Python 2 – Try It Online")
[Answer]
# plain TeX, 29 bytes
```
\def~#1x{{#1x_#1x^#1x}}~~~~~x
```
That outputs what others have output. But if we need the code to be compilable it would be 6 bytes more
```
\def~#1x{{#1x_#1x^#1x}}$~~~~~x$\bye
```
**Explanation**
`~` is an [active character](http://www.tex.ac.uk/FAQ-activechars.html) in TeX, so we can give it a (new) definition.
`\def~#1x{{#1x_#1x^#1x}}` defines `~` as a macro, so that when TeX sees `~`, it does the following: 
* Read everything up to the next `x`, and call that `#1` (pattern-matching).
* Replace the whole thing with `{#1x_#1x^#1x}`
For example, `~ABCx` would get replaced with `{ABCx_ABCx^ABCx}`.
When `~~~~~x` is used, `#1` is `~~~~`, so the whole thing gets replaced with `{~~~~x_~~~~x^~~~~x}`. And so on.
Once we have the long string, we can print it out to terminal with `\message` (and ending with a `\bye` so TeX stops), so `\message{~~~~~x}\bye`. Or typeset the resulting expression (as a mathematical formula), by surrounding it in `$`s : so `$~~~~~x$\bye`.
[Answer]
# [SOGL V0.12](https://github.com/dzaima/SOGL), ~~16~~ 12 [bytes](https://github.com/dzaima/SOGL/blob/master/chartable.md)
```
 x5{"{^_}”;∑
```
[Try it Here!](https://dzaima.github.io/SOGLOnline/?code=JTIweDUlN0IlMjIlN0IlNUVfJTdEJXUyMDFEJTNCJXUyMjEx)
Port of Erik The Outgolfer's [Python 2 answer](https://codegolf.stackexchange.com/a/143276/59183)
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 17 bytes
```
'x5F'x¡"{x^x_x}"ý
```
[Try it online!](https://tio.run/##MzBNTDJM/f9fvcLUTb3i0EKl6oq4iviKWqXDe///BwA "05AB1E – Try It Online")
**Explanation**
```
'x                  # push "x"
  5F                # 5 times do
    'x¡             # split on "x"
       "{x^x_x}"ý   # join on "{x^x_x}"
```
**Other programs at the same byte-count include**
```
"{x^x_x}"©4F'x¡®ý
'x5F'x"{x^x_x}".:
```
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), ~~44~~ 35 bytes
```
"'x'"+"-replace'x','{x^x_x}'"*5|iex
```
[Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/X0m9Ql1JW0m3KLUgJzE5FcjTUa@uiKuIr6hVV9IyrclMrfj//79GdHJGYlF0bKx6UUZlSUZusbomAA "PowerShell – Try It Online")
Uses string multiplication to repeatedly `-replace` `x`es with the sub- and super-scripts, then output.
*Saved 9 bytes thanks to Joey.*
[Answer]
# [MATL](https://github.com/lmendo/MATL), ~~21~~ 20 bytes
```
'x'XJ5:"J'{x^x_x}'Zt
```
-1 byte thanks to *Giuseppe*
[Try it online!](https://tio.run/##y00syfn/X71CPcLL1ErJS726Iq4ivqJWPark/38A "MATL – Try It Online")
[Answer]
## JavaScript (ES6), ~~45~~ ~~42~~ 37 bytes
```
f=n=>n>4?'x':[...'{^_}'].join(f(-~n))
```
Edit: Saved ~~3~~ 2 bytes thanks to @Arnauld. Specifying 5 still costs me 2 bytes; this ~~41~~ ~~40~~ 35-byte version takes a parameter instead:
```
f=n=>n?[...'{^_}'].join(f(n-1)):'x'
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 13 bytes
```
'x5F"{^_}"Ssý
```
[Try it online!](https://tio.run/##MzBNTDJM/f9fvcLUTak6Lr5WKbj48N7//wE "05AB1E – Try It Online")
Port of my Python 2 answer.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 12 bytes
```
”x“{^_}”j$5¡
```
[Try it online!](https://tio.run/##y0rNyan8//9Rw9yKRw1zquPia4HMLBXTQwv//wcA "Jelly – Try It Online")
Port of my Python 2 answer.
[Answer]
# [Japt](https://github.com/ETHproductions/japt/), ~~21~~ ~~20~~ 18 bytes
```
5Æ="\{^_}"¬qUª'xÃÌ
```
[Test it](https://ethproductions.github.io/japt/?v=1.4.5&code=NcY9Ilx7Xl99IqxxVaoneMPM&input=)
---
## Explanation
```
5Æ             Ã
```
Generate an array of length 5 and map over it.
```
"\{^_}"¬
```
Split a string to an array of characters
```
qUª'x
```
Rejoin (`q`) to a string using the current value of `U` or (`ª`) `"x"`.
```
=
```
Assign the result of that to `U`.
```
Ì
```
Get the last element in the array.
---
## Alternatives, 18 bytes
Same as above but reducing the array after it's been created.
```
5o r@"\{^_}"¬qX}'x
```
[Test it](https://ethproductions.github.io/japt/?v=1.4.5&code=NW8gckAiXHteX30irHFYfSd4&input=)
The recursive option.
```
>4©'xª"\{^_}"¬qßUÄ
```
[Test it](https://ethproductions.github.io/japt/?v=1.4.5&code=PjSpJ3iqIlx7Xl99Iqxx31XE&input=)
[Answer]
# [Java (OpenJDK 8)](http://openjdk.java.net/), ~~179~~ 167 bytes
@Neil port
```
interface Y{static void main(String[]a){System.out.println(t.apply(1));}java.util.function.Function<Integer,String>t=N->N>0?Y.t.apply(N-1).replace("x","{x^x_x}"):"x";}
```
[Try it online!](https://tio.run/##NY6xCoMwFEV/RTIloI@61tZuhS4uTlLaEjRKrCYhPiUifnsaaLvdc4dzb88XnmgjVN@8vZcKhW15LaJqm5CjrKNFyyYauVS0RCtVd39wtpXrhGIEPSOYUOKgKAI3Zlhpyli298EKM8oB2lnVKLWC6y@cbmGjEzb@6nI8F0le5IdLBX9FkaQMrDBDOEKJIzHZ3NO93E7YMWC2e/8B "Java (OpenJDK 8) – Try It Online")
[Answer]
# Wolfram Language (*Mathematica*) - 40 characters
Summarizing 3 best answers [here](http://community.wolfram.com/groups/-/m/t/1188472):
### 40 bytes:
```
Nest["{"<>#<>"_"<>#<>"^"<>#<>"}"&,"x",5]
```
### 41 bytes:
```
Nest[StringReplace["x"->"{x^x_x}"],"x",5]
```
### 44 bytes:
```
Last@SubstitutionSystem["x"->"{x^x_x}","x",5]
```
[Answer]
# [C (gcc)](https://gcc.gnu.org/), 82 bytes
```
O(o){o--?_(125,O(o,_(95,O(o,_(94,O(o,_(123))))))):_(120);}main(){O(5);}
```
[Try it online!](https://tio.run/##S9ZNT07@/99fI1@zOl9X1z5ew9DIVAfI1YnXsIQzTKAMQyNjTQiwAnEMNK1rcxMz8zQ0q/01TIGc////JaflJKYX/9d1ibctKC1JzkgsAgA "C (gcc) – Try It Online")
[Answer]
# Pyth, ~~17~~ ~~16~~ 13 bytes
```
jF+\x*5]"{^_}
```
[Try it online!](https://tio.run/##K6gsyfj/P8tNO6ZCyzRWqTouvvb/fwA)
Python 3 translation:
```
from functools import*;print(reduce(lambda x,y:x.join(y),["x"]+5*["{^_}"]))
```
]