formelsammlung/src/util/tikz_macros.tex
2025-02-15 16:01:05 +01:00

115 lines
3.6 KiB
TeX

\tikzset{
% bands
sc band con/.style={ draw=fg0, thick},
sc band val/.style={ draw=fg0, thick},
sc band vac/.style={ draw=fg1, thick},
sc band/.style={ draw=fg0, thick},
sc fermi level/.style={draw=fg-aqua,dashed,thick},
% electron filled
sc occupied/.style={
pattern=north east lines,
pattern color=fg-aqua,
draw=none
},
% materials
sc p type/.style={ draw=none,fill=bg-yellow!20},
sc n type/.style={ draw=none,fill=bg-blue!20},
sc metal/.style={ draw=none,fill=bg-purple!20},
sc oxide/.style={ draw=none,fill=bg-green!20},
sc separate/.style={ draw=fg0,dotted},
}
\newcommand\drawDArrow[4]{
\draw[<->] (#1,#2) -- (#1,#3) node[midway,right] () {#4};
}
% Band bending down at L-R interface: BendH must be negative
% need two functions for different out= angles, or use if else on the sign of BendH
\newcommand\leftBandAuto[2]{
\directlua{
if \tkLBendH == 0 then
tex.print([[(\tkLx,#2) \ifblank{#1}{}{node[anchor=east] \detokenize{{#1}}} -- (\tkLW,#2) ]])
else
if \tkLBendH > 0 then
angle = 180+45
else
angle = 180-45
end
tex.sprint([[(\tkLx,#2) \ifblank{#1}{}{node[anchor=east] \detokenize{{#1}}}
-- (\tkLW-\tkLBendW,#2) to[out=0,in=]], angle, [[](\tkLW,#2+\tkLBendH)]])
end
}
% % \ifthenelse{\equal{\tkLBendH}{0}}%
% % {%
% \ifthenelse{\tkLBendH > 0}%
% {\pgfmathsetmacro{\angle}{-45}}%
% {\pgfmathsetmacro{\angle}{45}}%
% % }
}
\newcommand\rightBandAuto[2]{
\directlua{
if \tkRBendH == 0 then
%-- tex.print([[\rightBand{#1}{#2}]])
tex.print([[(\tkRx,#2) -- (\tkW,#2)]]) %-- \ifblank{#1}{}{node[anchor=west] \{#1\}}]])
else
if \tkRBendH > 0 then
angle = -45
else
angle = 45
end
tex.sprint([[(\tkRx,#2+\tkRBendH) to[out=]], angle, [[,in=180] (\tkRx+\tkRBendW,#2) -- (\tkW,#2) ]])
%-- \ifblank{#1}{}{node[anchor=west] \{#1\}} ]])
end
if "\luaescapestring{#1}" \string~= "" then
tex.print([[node[anchor=west] \detokenize{{#1}} ]])
end
}
% \ifthenelse{\equal{\tkRBendH}{0}}%
% {\rightBand{#1}{#2}}
% {%
% \ifthenelse{\tkRBendH > 0}%
% {\pgfmathsetmacro{\angle}{-45}}%
% {\pgfmathsetmacro{\angle}{45}}%
% (\tkRx,#2+\tkRBendH) to[out=45,in=180] (\tkRx+\tkRBendW,#2) -- (\tkW,#2)
% \ifblank{#1}{}{node[anchor=west]{#1}}
% }
}
\newcommand\leftBandDown[2]{
(\tkRx,#2+\tkRBendH) to[out=45,in=180] (\tkRx+\tkRBendW,#2) -- (\tkW,#2)
\ifblank{#1}{}{node[anchor=west]{#1}}
}
\newcommand\rightBandDown[2]{
(\tkRx,#2+\tkRBendH) to[out=45,in=180] (\tkRx+\tkRBendW,#2) -- (\tkW,#2)
\ifblank{#1}{}{node[anchor=west]{#1}}
}
% Band bending down at L-R interface: BendH must be positive
\newcommand\leftBandUp[2]{
(\tkLx,#2) \ifblank{#1}{}{node[anchor=east]{#1}}
-- (\tkLW-\tkLBendW,#2) to[out=0,in=180+45] (\tkLW,#2+\tkLBendH)
}
\newcommand\rightBandUp[2]{
(\tkRx,#2+\tkRBendH) to[out=-45,in=180] (\tkRx+\tkRBendW,#2) -- (\tkW,#2)
\ifblank{#1}{}{node[anchor=west]{#1}}
}
% Straight band
\newcommand\leftBand[2]{
(\tkLx,#2) \ifblank{#1}{}{node[anchor=east]{#1}} -- (\tkLW,#2)
}
\newcommand\rightBand[2]{
(\tkRx,#2) -- (\tkW,#2) \ifblank{#1}{}{node[anchor=west]{#1}}
}
\newcommand\drawAxes{
\draw[->] (0,0) -- (\tkW+0.2,0) node[anchor=north] {$x$};
\draw[->] (0,0) -- (0,\tkH+0.2) node[anchor=east] {$E$};
}
\newcommand\tkXTick[2]{
\pgfmathsetmacro{\tickwidth}{0.1}
\draw (#1, -\tickwidth/2) -- (#1, \tickwidth/2) node[anchor=north] {#2};
}
\newcommand\tkYTick[2]{
\pgfmathsetmacro{\tickwidth}{0.1}
\draw (-\tickwidth/2, #1) -- (\tickwidth/2,#1) node[anchor=east] {#2};
}