From eaf9ceea28753247dad7218336b827192d99da98 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Mon, 3 May 2021 01:05:50 +0200 Subject: [PATCH] improve includeDiagram macro --- tex/latex/local/ntnu/ntnu-math.sty | 22 +-------- tex/latex/local/ntnu/ntnu.sty | 72 +++++++++++++++++++++++++++--- 2 files changed, 67 insertions(+), 27 deletions(-) diff --git a/tex/latex/local/ntnu/ntnu-math.sty b/tex/latex/local/ntnu/ntnu-math.sty index 309f553..3d4f50d 100644 --- a/tex/latex/local/ntnu/ntnu-math.sty +++ b/tex/latex/local/ntnu/ntnu-math.sty @@ -6,6 +6,7 @@ \RequirePackage{pgfplots} \RequirePackage{amssymb} \RequirePackage{amsthm} +\RequirePackage{ntnu} % ░█▀▀░▄▀▄░█░█░█▀█░▀█▀░▀█▀░█▀█░█▀█░█▀▀ @@ -27,27 +28,6 @@ % ░█░█░█▀▄░█▀█░█▀▀░█▀█░▀▀█ % ░▀▀▀░▀░▀░▀░▀░▀░░░▀░▀░▀▀▀ - -\RequirePackage{tcolorbox} - -\newtcolorbox{coloredgraphbox}[1][]{ - colframe=ntnublue, - arc=0pt, - outer arc=0pt - colback=white, - boxrule=3pt, - #1 -} - -%TODO: Make resizable and float -\newenvironment{mgraphbox}[1][]{ - \begin{center} - \begin{coloredgraphbox}[#1] -}{ - \end{coloredgraphbox} - \end{center} -} - %TODO: Directed graphs, trees % ░▀█▀░█▀█░█▀▄░█░░░█▀▀░█▀▀ diff --git a/tex/latex/local/ntnu/ntnu.sty b/tex/latex/local/ntnu/ntnu.sty index 73d81a5..5027cab 100644 --- a/tex/latex/local/ntnu/ntnu.sty +++ b/tex/latex/local/ntnu/ntnu.sty @@ -182,13 +182,31 @@ \addcontentsline{toc}{subsubsubsection}{\theenumiii} } +% ░█▀▄░▀█▀░█▀█░█▀▀░█▀▄░█▀█░█▄█░█▀▀ +% ░█░█░░█░░█▀█░█░█░█▀▄░█▀█░█░█░▀▀█ +% ░▀▀░░▀▀▀░▀░▀░▀▀▀░▀░▀░▀░▀░▀░▀░▀▀▀ -% ░█▄█░▀█▀░█▀▀░█▀▀ -% ░█░█░░█░░▀▀█░█░░ -% ░▀░▀░▀▀▀░▀▀▀░▀▀▀ +\RequirePackage{xparse} +\RequirePackage{xkeyval} + +\newtcolorbox{coloredgraphbox}[1][]{ + colframe=ntnublue, + arc=0pt, + outer arc=0pt + colback=white, + boxrule=3pt, + #1 +} + +%TODO: Make resizable and float +\newenvironment{mgraphbox}[1][]{ + \begin{center} + \begin{coloredgraphbox}[#1] +}{ + \end{coloredgraphbox} + \end{center} +} -\RequirePackage{float} -\RequirePackage[export]{adjustbox} \newcommand{\pic}[1]{ \begin{figure}[H] @@ -196,7 +214,49 @@ \end{figure} } -\ProcessOptions\relax +\newcommand{\@ifdefined}[2]{ + \@ifundefined{#1}{}{#2} +} + +\define@key{inputDiagram}{width}{\def\id@width{#1}} +\define@key{inputDiagram}{scale}{\def\id@scale{#1}} +\define@key{inputDiagram}{caption}{\def\id@caption{#1}} +\define@key{inputDiagram}{label}{\def\id@label{#1}} +\define@boolkey{inputDiagram}{pdf}{} + +\NewDocumentCommand{\includeDiagram}{ o m }{ + \begingroup + + \setkeys{inputDiagram}{width=\linewidth, scale=1, pdf=false} + \IfValueT{#1}{\setkeys{inputDiagram}{#1}} + + \begin{mgraphbox}[width=\id@width] + \begin{figure}[H] + \begin{center} + \scalebox{\id@scale}{ + \ifKV@inputDiagram@pdf + \includegraphics{#2} + \else + \input{#2} + \fi + } + + \@ifdefined{id@caption}{\caption{\id@caption}} + + \@ifdefined{id@label}{\label{\id@label}} + \end{center} + \end{figure} + \end{mgraphbox} + + \endgroup +} + +% ░█▄█░▀█▀░█▀▀░█▀▀ +% ░█░█░░█░░▀▀█░█░░ +% ░▀░▀░▀▀▀░▀▀▀░▀▀▀ + +\RequirePackage{float} +\RequirePackage[export]{adjustbox} \setlength{\parindent}{0cm}