[Tex/LaTex] fa-home icon using TikZ

tikz-pgf

I am trying to get a fa-home icon in a document that I am compiling using pdflatex. I am aware that fa-home works only under XeLaTeX. Is there anyway, I could reproduce this icon using Tikz drawing? Any input will be greatly appreciated.

Best Answer

You cat take the SVG version of Font Awesom copy the code of ha-home (unicode: f015) in \fill svg={...}; by scaling (and yshifting) using the information from <font-face units-per-em="1792" ascent="1536" descent="-256" />. Put all this in a pic and use it like this \tikz\pic{fa-home};.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{svg.path}

\tikzset {
    fa-home/.pic = {\fill[scale=1em/1792] svg {M1408 544v-480q0 -26 -19 -45t-45 -19h-384v384h-256v-384h-384q-26 0 -45 19t-19 45v480q0 1 0.5 3t0.5 3l575 474l575 -474q1 -2 1 -6zM1631 613l-62 -74q-8 -9 -21 -11h-3q-13 0 -21 7l-692 577l-692 -577q-12 -8 -24 -7q-13 2 -21 11l-62 74q-8 10 -7 23.5t11 21.5 l719 599q32 26 76 26t76 -26l244 -204v195q0 14 9 23t23 9h192q14 0 23 -9t9 -23v-408l219 -182q10 -8 11 -21.5t-7 -23.5z};}
}

\begin{document}
\foreach \size in {tiny,scriptsize, footnotesize, small, normalsize, large, Large, LARGE, huge, Huge}
{{\csname\size\endcsname \size \ \tikz\pic{fa-home};}\par}

\end{document}

enter image description here

The only problem is that when you compile you get ! Dimension too large.. One possible solution is to divide all coordinates by 1792 and then to use them with simple scale=1em. Here is the final code :

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{svg.path}

\tikzset {
    fa-home/.pic = {\fill[scale=1em] svg {M0.786 0.304v-0.268q0.0 -0.015 -0.011 -0.025t-0.025 -0.011h-0.214v0.214h-0.143v-0.214h-0.214q-0.015 0.0 -0.025 0.011t-0.011 0.025v0.268q0.0 0.001 0.0 0.002t0.0 0.002l0.321 0.265l0.321 -0.265q0.001 -0.001 0.001 -0.003zM0.91 0.342l-0.035 -0.041q-0.004 -0.005 -0.012 -0.006h-0.002q-0.007 0.0 -0.012 0.004l-0.386 0.322l-0.386 -0.322q-0.007 -0.004 -0.013 -0.004q-0.007 0.001 -0.012 0.006l-0.035 0.041q-0.004 0.006 -0.004 0.013t0.006 0.012 l0.401 0.334q0.018 0.015 0.042 0.015t0.042 -0.015l0.136 -0.114v0.109q0.0 0.008 0.005 0.013t0.013 0.005h0.107q0.008 0.0 0.013 -0.005t0.005 -0.013v-0.228l0.122 -0.102q0.006 -0.004 0.006 -0.012t-0.004 -0.013z};}
}

\begin{document}

\foreach \size in
  {tiny,scriptsize, footnotesize, small, normalsize, large, Large, LARGE, huge, Huge}
  {
      {\csname\size\endcsname \size \ \tikz\pic{fa-home};}\par
  }
\end{document}

If you want to use the descent="-256" information, you can yshift by -256 like this \fill[scale=1em/1792, yscale=-256] and then use it with baseline like this \tikz[baseline]\pic{fa-home}; (if you use the second code, you should replace -256 by -256/1792 = 0.14)