본문 바로가기

D2Lang

[D2Lang] 5. D2의 Text & Code를 알아보자!

728x90

오늘은 Text와 code를 삽입하는 방법에 대해 알아보겠습니다.

 

1번째 코드입니다.

#은 주석입니다.

explanation: |md
  # up mark
  context
|

explanation2: |md
  # can use markdown
  context
|

explanation -> explanation2

plankton -> formula: will steal
formula: {
  equation: |latex
    \\lim_{h \\rightarrow 0 } \\frac{f(x+h)-f(x)}{h}
  |
}

아래의 사진은 결과입니다.

upmark와 can use markdown은 마크다운 문법을 사용했으며 옆의 plankton과 formula는 LaTex(MathJax)를 통해 수식을 나타낸 것입니다.

 

|사용할 속성

|

 

으로 container뒤에 적어 주시면 아래와 같이 출력 되게 만들 수 있습니다.

markdown과 LaTex는 따로 설명 드리지 않겠습니다만 “\”의 경우 escape문자다 보니 “\\”로 사용해야 합니다.

 

예) 기존 MathJex 문법 \alpha → D2Lang에서 사용하는 경우 \\alpha

또한 아직 줄바꿈이 추가되지 않았지만 추후 displaylines를 통해 개선한다 합니다.

결과 1

코드와 텍스트를 출력하는 방법에 대해 살펴보겠습니다.

grid-rows: 3

title: it is just text {
  shape: text
  style: {
    font-size: 55
    italic: true
    bold: true
    underline: true
  }
}

code: |c
  printf("%d", 10);
|

my_code1: ||ts
  declare function getSmallPet(): Fish | Bird;
||

my_code2: |||ts
  declare function getSmallPet(): Fish | Bird;
  const works = (a > 1) || (b < 2)
|||

my_code3: |`ts
  declare function getSmallPet(): Fish | Bird;
  const works = (a > 1) || (b < 2)
`|

일반 shape: text속성으로 일반 텍스트로 만들 수 있고 그 안에 속성으로 세부적인 텍스트를 정할 수 있습니다.

코드의 경우에는 | 뒤에 언어 이름을 적어서 사용하면 됩니다.

 

언어의 문법에 따라 |이 사용되기 때문에 텍스트를 출력하는 여러 방법이 지원되고 있습니다.

||~||을 두개 붙여 사용하는 방법 |||~|||이나 |`~`|을 사용하는 방법이 있습니다.

 

출력은 아래와 같습니다.

결과 2

다음으로는 지원하는 LaTex 예제를 보고 마치겠습니다.

amscd plugin: {
  ex: |tex
    \\begin{CD} B @>{\\text{very long label}}>> C S^{{\\mathcal{W}}_\\Lambda}\\otimes T @>j>> T\\\\ @VVV V \\end{CD}
  |
}

braket plugin: {
  ex: |tex
    \\bra{a}\\ket{b}
  |
}

cancel plugin: {
  ex: |tex
    \\cancel{Culture + 5}
  |
}

color plugin: {
  ex: |tex
    \\textcolor{red}{y} = \\textcolor{green}{\\sin} x
  |
}

gensymb plugin: {
  ex: |tex
    \\lambda = 10.6\\,\\micro\\mathrm{m}
  |
}

mhchem plugin: {
  ex: |tex
    \\ce{SO4^2- + Ba^2+ -> BaSO4 v}
  |
}

physics plugin: {
  ex: |tex
    \\var{F[g(x)]}
    \\dd(\\cos\\theta)
  |
}

multilines: {
  ex: |tex
    \\displaylines{x = a + b \\\\ y = b + c}
    \\sum_{k=1}^{n} h_{k} \\int_{0}^{1} \\bigl(\\partial_{k} f(x_{k-1}+t h_{k} e_{k}) -\\partial_{k} f(a)\\bigr) \\,dt
  |
}

# Just to separate into two rows
amscd plugin -> braket plugin: {style.opacity: 0}
cancel plugin -> color plugin: {style.opacity: 0}
gensymb plugin -> mhchem plugin: {style.opacity: 0}
physics plugin -> multilines: {style.opacity: 0}

지원하고 있는 플러그인입니다.

결과3

LaTex의 문법같은 경우는 D2Lang이 아니기 때문에 따로 설명드리지않겠습니다.

이것으로 마치겠습니다.