master
Ondřej Hruška 6 years ago
parent b91569ad2d
commit c9093afd84
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 3
      build.sh
  2. 48
      ch.existing_solutions.tex
  3. 20
      ch.introduction.tex
  4. 51
      ch.requirements.tex
  5. 7
      clean.sh
  6. BIN
      ctu_logo_black.pdf
  7. BIN
      ctu_logo_blue.pdf
  8. 384
      ctuth-core.tex
  9. 195
      ctuth-names.tex
  10. 997
      ctuth-pkg.tex
  11. 234
      ctuth-templates.tex
  12. 64
      ctuthesis.cls
  13. 170
      document_config.tex
  14. 20
      sec_abstract.tex
  15. 16
      sec_declaration.tex
  16. 6
      sec_thanks.tex
  17. 7
      thesis.bib
  18. BIN
      thesis.pdf
  19. 30
      thesis.tex
  20. 3
      vlna.sh
  21. BIN
      zadani-zakryto.pdf

@ -0,0 +1,3 @@
#!/bin/bash
pdflatex -shell-escape -synctex=1 -interaction=nonstopmode thesis.tex

@ -0,0 +1,48 @@
\chapter{Existing Solutions}
The idea of making it easier to interact with low level hardware from a PC is not new. Several solutions to this problem have been developed over the past years, each with its own advantages and drawbacks. Some of the existing solutions will be presented in this section.
\section{Bus Pirate}
\todo{pictures}
http://dangerousprototypes.com/blog/about/
Bus Pirate, developed by \todo{link}Ian Lesnet at Dangerous Prototypes and manufactured by Seeed Studio\todo{link}, is a "tinkering kit" providing access to hardware interfaces like SPI, I$^2$C, USART and 1-Wire (those will be described later \todo{link to actual place}), as well as frequency measurement and direct pin access.
The board aims to make it easy for the user to familiarize themself with new chips and modules; it also provides a range of programming interfaces for flashing microcontroller firmwares and memories. It communicates with the PC using a FTDI USB-serial bridge
Bus Pirate is open source and in scope it is similar to what we want to achieve here. It can be scripted and controlled from languages like Python or Perl, connects to USB and provides a wide selection of hardware interfaces.
The board is based on a PIC16 microcontroller running at 32\,MHz. Its analog/digital converter (ADC) only has a resolution of 10 bits (1024 levels). There is no digital/analog converter (DAC) available on the chip, making applications that require a varied output voltage more difficult. Another limitation of the board is its low number of GPIO pins which may be insufficient for certain applications, such as multi-channel sampling, parallel interfaces, or connecting multiple different devices at once.
Those limitations, however, hardly impede on Bus Pirate's primary purpose, which is to provide an easy access to digital buses.
\section{Raspberry Pi}
\todo[inline]{link, pictures}
Another device worth mentioning, albeit of a very different kind, is the Raspberry Pi. It is a belief of the author that the inclusion of a GPIO (\textit{general purpose I/O}) header on the Raspberry Pi mini-computers was a significant factor in their success in the hobbyist circles and school environments. This GPIO header exposes various hardware interfaces to user programs running on the computer.
The responsibility of controlling the experimental hardware then lies on the user application which also provides the user interface, much simplifying the development process. The control application can be written in almost any programming language the experimenter chooses; the most popular choices appear to be Python and JavaScript. The embedded firmware, should an external microcontroller be used instead, would typically have to be written in C, C++, or assembly.
A disadvantage of using a Raspberry Pi's GPIO header is that the experiments would have to be conducted directly on the mini-computer instead of using the more powerful computer the researchers already have available\footnote{An exception may be the use of such a device in developing countries, where the Raspberry Pi serves as a low-cost PC on its own.}. This introduces complications with data export or remote control. Further, should the experiment use a software package like MATLAB, installing it on the ARM-based Raspberry Pi may prove problematic.
\section{The Firmata protocol}
\todo[inline]{links}
\todo[inline]{Move this elsewhere}
Firmata is a serial communication protocol based on MIDI (\textit{Musical Instrument Digital Interface}) for passing data to and from embedded microcontrollers. MIDI is primarily used for attaching electronic musical instruments, such as synthesizers, keyboards, mixers etc., to each other or to a PC.
Firmata was designed for use with the Arduino firmware to allow easy construction of user programs (called \textit{sketches} in the Arduino environment) that communicate with a client application running on the PC without having to worry about technical details.\todo{citation}
Implementing the Firmata protocol in a universal hardware interfacing module would make it possible to use existing Firmata client libraries. However, it is constricted by the limitations of the encompassing MIDI protocol and offers little flexibility.
\section{Professional DAQ modules}
There are several offerings from professional laboratory instrument manufacturers, however their common property is a very high price. This renders them inaccessible for users with a limited budget, such as hobbyists or students who would like to keep such a device for personal use. An example falling into this category is the National Instruments "I²C/SPI Interface Device", which also includes several GPIO lines.
\todo[inline]{http://www.ni.com/en-gb/shop/select/i2c-spi-interface-device}
The decoding of hardware buses like USART, SPI or I²C is a common feature in digital storage oscilloscopes, as is the sampling of digital channels with "logic analyzer" add-ons. They are valuable debugging tools, but hardly ever provide a way to interact with the bus beyond passively intercepting an ongoing communication.

@ -0,0 +1,20 @@
\chapter{Introduction}
Prototyping, design evaluation and the measurement of physical properties in experiments make a daily occurrence in the engineering praxis. This task involves the generation and capture of electrical signals coming to and from specialized sensors, actuators and other circuitry. As the technology advanced, driven by the consumer electronics market in the pursuit of miniaturization and lower cost, a multitude of integrated sensors with digital interfaces became available. Those devices can provide a sufficient accuracy and precision for the task at hand while keeping the circuit complexity down by integrating a large portion of the necessary circuit, often including the sensor itself, on a single chip or in a compact module.
The drive for miniaturization and the advent of modern hardware buses, in particular USB (Universal Serial Bus), however, simultaneously lead to the disappearance of low level computer ports, such as the once ubiquitous parallel port, that would provide an easy way of connecting those digital devices and low level hardware in general to personal computers.
With those developments, we on the one hand have an easy access to interesting integrated devices that would make the mentioned experiments and evaluations easier, on the other, our means of interfacing them have become more complicated. When an engineer today wants to perform some measurements using a digital sensor, they are often left having to implement an embedded firmware for a microcontroller that can be connected to the PC through USB, commonly through a USB-USART adapter. This approach lets one optimize the solution for a particular task and possibly achieve higher performance, however it is time-consuming and requires knowledge of the embedded system design that is entirely removed from the desired measurement.
Clearly it would be advantageous to have a way to easily attach those integrated devices and low level hardware in general to a PC without having to burden ourselves with technicalities of the connection. The design and implementation of such a system is the object of this work.

@ -0,0 +1,51 @@
\chapter{Goals and Requirements}
This chapter analyzes the project requirements and presents a vision of the final outcome.
\section{Project Name}
Referring to the project only as "the project" or "the device" would be clumsy and lead to confusion. Henceforth, the project should be known as \textbf{GEX}, an acronym originating in the term \textit{GPIO Expander}, which, although not describing its scope perfectly, alludes to the project's primary purpose of providing low level GPIO capabilities to personal computers.
\section{Expected Use-Cases}
A first step must necessarily be to consider the situations in which the device is expected to be useful. As was mentioned in the introduction, one of the problems addressed is making it possible to easily attach electronic circuits and components to a PC. This could be in order to familiarize oneself with a new chip or a module, to measure a characteristic curve of a component, to collect experimental data from a test setup, or, for instance, to control a positioning motor.
The applications can have a temporary character, a simple setup that is used once and then dismantled, or a more permanent one. An example of the latter could be laboratory tasks where the measurement framework and user interface is prepared beforehand and connecting the circuit or simply performing measurements while varying some physical properties is left as an exercise to students. Another example could be the use of GEX as a data acquisition module, replacing more expensive professional devices.
As such, the device must be easy to configure without having to modify the embedded firmware and should provide the hardware interfaces and functions that are be needed for such applications. The module can be either attached directly to a PC via USB or controlled wirelessly. It would also be possible to design it as a PCI Express card, however that would limit its use to desktop computers and make the installation and software support more complicated. The wireless connection will find use in mobile robotic projects, when installed in less accessible places, or outdoors.
\section{Hardware Interfaces to Implement}
Given the project's broad range of potential applications, predicting precisely what hardware interfaces and connections might be needed is hardly possible. A good approach appears to be to implement the most common protocols and interfaces and provide access to selected low level features offered by the used microcontroller, like timers and direct pin access, while keeping the firmware open to future expansions should the need arise.
\subsection{Direct Digital Input/Output}
The most basic form of interaction with hardware is by changing the logic levels of output pins and reading input pins. With this feature alone it would be possible to analyze logic circuits, trigger some transient effect we want to observe using an oscilloscope, read a contact state, sense a button push, drive LED displays and more. Almost anything digital that doesn't require precise or fast timing could be achieved by this simple function.
To make this feature more versatile, it should be possible to receive an asynchronous event on a pin state change, avoiding the need for polling loops in the control application.
\subsection{Common Digital Buses}
A popular way to attach peripheral devices to a microcontroller are hardware buses, the most well known of which are SPI (\textit{Serial Peripheral Interface}), I$^2$C (or IIC, \textit{Inter-Integrated-Circuit}) and USART (\textit{Universal Synchronous Asynchronous Receiver Transmitter}), in the asynchronous variant referred to as UART. A large majority of peripheral integrated circuits, digital-interface sensors and modules can be accessed using those buses. They also have hardware support in most microcontrollers, removing the burden of precise timing from the firmware.
Another hardware interface that might fall into this category is I$^2$S (or IIS, \textit{Inter IC Sound}). I$^2$S is used for streaming sampled audio streams or analog samples and finds far less use than the previously mentioned buses.
More information about those interfaces (excluding I$^2$S) can be found in later chapters. \todo{link to actual place}
\subsection{Specialized Buses}
Some devices exist that do not use any of the common buses, instead requiring their own proprietary protocol. An example of this group is the Dallas Semiconductor\footnote{Acquired by Maxim Integrated in 2001}\todo{source} 1-Wire bus, used by the popular DS18x20 digital thermometers. Another example might be some types of addressable LED strips.
A common characteristic of those buses is that they require precise timing and have no native hardware support like the above mentioned common buses. This means that we can't depend on the direct GPIO access and have to implement low level driver utilities to achieve reliable communication.
\subsection{Analog Input/Output}
Microcontrollers typically include an ADC (\textit{Analog to Digital Converter}) with a 10-12 bits of resolution, sometimes accompanied by a DAC (\textit{Digital to Analog Converter}), its output counterpart. In the lack of a real DAC, the analog output, albeit with worse dynamic parameters, can be realized using a PWM signal (\textit{Pulse Width Modulation}, pulse train) followed by a low-pass filter.
While we mainly focused on digital interfaces thus far, providing means of generating and capturing analog signals is also valuable. This capability makes it possible to read sensors with voltage output and it can substitute a simple oscilloscope when sampled periodically at a sufficient frequency. Analog input channels, even with lower resolution or sample rate, may in some cases avoid the need for a dedicated acquisition device.
In conjunction, the analog output and input can be used for automated characterization of electronic components, such as diodes. Should the analog output be modulated, we could further use them to measure frequency-dependent characteristics, such as the frequency response of analog filters.

@ -0,0 +1,7 @@
#!/bin/bash
git rm -r --cached .
git add .
git clean -xf

Binary file not shown.

Binary file not shown.

@ -0,0 +1,384 @@
%!TEX ROOT = ctutest.tex
\ProvidesExplFile{ctuth-core.tex}%
{2015/11/15}{0.1 t1511151022}%MY TIMESTAMP HERE {0.1}
{"Core"\space part\space of\space the\space class\space ctuthesis}
%%% GENERAL LaTeX3 THINGIES
\cs_generate_variant:Nn \keys_set:nn { nx }
\cs_generate_variant:Nn \tl_if_eq:nnTF { xn }
\cs_generate_variant:Nn \seq_gconcat:NNN { cc }
\cs_generate_variant:Nn \str_if_eq:nnTF { xn }
\skip_new:N \g_ctuthesis_tempa_skip
%%% CLASS SETUP, FIELDS, TEMPLATES, THEMES
% Set allowed languages: No other languages can ever be main, title or second
\tl_gset:Nn \g_ctuthesis_alllanguages_tl {{czech}{english}{slovak}}
% Error message for using \ctuprocess twice
\msg_new:nnn { ctuthesis } { ctuprocess-twice } { The~macro~ \token_to_str:N \ctuprocess\ should~
be~used~only~once~in~preamble. }
% Error message for not using \ctuprocess at all
\msg_new:nnn { ctuthesis } { ctuprocess-none } { It~is~necessary~to~use~the~
macro~ \token_to_str:N \ctuprocess\ once~in~the~preamble. }
%%% KEY-VALUE SETUP
% Two seqs: one for keys that need disabling after \documentclass,
% another one for keys that need disabling after \ctuprocess
\seq_new:N \g_ctuthesis_keys_nop_seq
\seq_new:N \g_ctuthesis_keys_nopost_seq
% Add the clist #2 into seq #1
\cs_new:Nn \ctuthesis_keys_add_no:nn {
\group_begin:
\seq_set_from_clist:Nn \l_temp_ctuthesis_a_seq { #2 }
\seq_gconcat:ccN { g_ctuthesis_keys_#1_seq } { g_ctuthesis_keys_#1_seq } \l_temp_ctuthesis_a_seq
\group_end:
}
% Error messages for the keyvalue interface
\msg_new:nnn { ctuthesis } { keys-unknown } { The~key~'#1'~is~not~known~to~the~
class~'ctuthesis'~and~will~be~ignored. }
\msg_new:nnn { ctuthesis } { keys-nopost } { The~key~'#1'~is~forbidden~after~
\token_to_str:N \ctuprocess \space and~will~be~ignored.~You~may~wish~to~
set~it~up~before. }
\msg_new:nnn { ctuthesis } { keys-nop } { The~key~'#1'~is~forbidden~in~
\token_to_str:N \ctusetup \space and~will~be~ignored.~Use~the~optional~argument~
of~ \token_to_str:N \documentclass \space to~set~it~up. }
% Very standard unknown key treatment
\keys_define:nn { ctuthesis } {
unknown .code:n = \msg_error:nnx { ctuthesis } { keys-unknown } { \l_keys_key_tl },
}
% Disables keys marked '#1' (either 'nop' or 'nopost')
\cs_new:Nn \ctuthesis_disable_keys:n {
\seq_map_inline:cn { g_ctuthesis_keys_#1_seq } {
\keys_define:nn { ctuthesis } {
##1 .code:n = \msg_error:nnx { ctuthesis } { keys-#1 } { ##1 },
}
}
}
% General keys
\tl_gset:Nn \g_ctuthesis_fontsize_tl {11pt}
\seq_new:N \g_ctuthesis_languages_seq
\keys_define:nn { ctuthesis } {
% Only 11pt fontsize is allowed
fontsize .choices:nn = { 11pt } { \tl_gset_eq:NN \g_ctuthesis_fontsize_tl \l_keys_choice_tl },
% Oneside option
oneside .bool_gset:c = { g_ctuthesis_switch_oneside_bool },
oneside .initial:n = { false },
twoside .meta:n = { oneside = false },
% Draft option
draft .bool_gset:c = { g_ctuthesis_switch_draft_bool },
draft .initial:n = { false },
% We use three languages:
% main for the work itself, ToC and LoFT
mainlanguage .choice:,
% title for the titlepage, thanks, declaration and abstract
titlelanguage .choice:,
% second is the language of second abstract. First abstract is in title language,
% second abstract is either in main language, or in English for Czech/Slovak theses
% or Czech for English theses. It will be set automatically.
secondlanguage .choice:,
% otherlanguages will be simply passed on to babel
otherlanguages .code:n =
\seq_set_from_clist:Nn \l_temp_ctuthesis_a_seq { #1 }
\seq_gconcat:NNN \g_ctuthesis_languages_seq \g_ctuthesis_languages_seq \l_temp_ctuthesis_a_seq
,
}
\ctuthesis_keys_add_no:nn { nop } { draft, fontsize, oneside, twoside }
\ctuthesis_keys_add_no:nn { nopost } { mainlanguage, titlelanguage, secondlanguage }
% Switches defaulting to false
\tl_map_inline:nn { {front-specification}{monochrome}{savetoner}{pkg-listings}{layout-short} } {
\keys_define:nn { ctuthesis } {
#1 .bool_gset:c = { g_ctuthesis_switch_#1_bool },
#1 .initial:n = { false },
}
}
\ctuthesis_keys_add_no:nn { nopost } { monochrome, savetoner, pkg-listings }
% Switches defaulting to true
\tl_map_inline:nn { {front-list-of-tables}{front-list-of-figures}{pkg-hyperref}{pkg-makeidx}{pkg-amsthm} } {
\keys_define:nn { ctuthesis } {
#1 .bool_gset:c = { g_ctuthesis_switch_#1_bool },
#1 .initial:n = { true },
}
}
\ctuthesis_keys_add_no:nn { nopost } { pkg-hyperref, pkg-makeidx }
% We allow the key 11pt along with the key fontsize
\tl_map_inline:nn { {11pt} } {
\keys_define:nn { ctuthesis } {
#1 .meta:n = { fontsize = #1 },
}
\ctuthesis_keys_add_no:nn { nop } { #1 }
}
% Basic fields that are not language-dependent
\tl_map_inline:nn { {author}{supervisor}{supervisor-specialist}{supervisor-address}{day}{month}{year}
{facultynum}{specification-file}{preprint} } {
\keys_define:nn { ctuthesis } {
#1 .tl_gset:c = { g_ctuthesis_field_#1_tl },
}
}
% Language-dependent keys and environments
\tl_map_inline:Nn \g_ctuthesis_alllanguages_tl {
% Various fields in various languages
\tl_map_inline:nn { {title}{subtitle}{university}{university-endl}{faculty}{department}
{doctype}{fieldofstudy}{subfieldofstudy}{keywords} } {
\keys_define:nn { ctuthesis } {
##1-#1 .tl_gset:c = g_ctuthesis_field_##1_#1_tl,
}
}
% Sets up the choice for each of the languages
\tl_map_inline:nn { {mainlanguage}{titlelanguage}{secondlanguage} } {
\keys_define:nn { ctuthesis } {
##1 / #1 .code:n =
\tl_gset:cn { g_ctuthesis_field_##1_tl } { #1 }
\seq_gput_right:Nn \g_ctuthesis_languages_seq { #1 },
}
}
% The abstract is now language-dependent
\NewEnviron { abstract-#1 } { \tl_gset:cV { g_ctuthesis_field_abstract_#1_tl } \BODY }
\tl_new:c { g_ctuthesis_field_abstract_#1_tl }
}
% "abstract" itself is not used, the language of the abstract has to be specified
\msg_new:nnn { ctuthesis } { abstract-forbidden } { The~environment~'abstract'~should~be~replaced~
by~'abstract-lang'~with~the~proper~language~specified. }
\DeclareDocumentEnvironment{ abstract }{ }{ \msg_error:nn { ctuthesis } { abstract-forbidden } }{ }
% "thanks" and "declaration" are fields, but set up as environments rather then KVs
\cs_undefine:c { thanks }
\NewEnviron { thanks } { \tl_gset:cV { g_ctuthesis_field_thanks_tl } \BODY }
\tl_new:c { g_ctuthesis_field_thanks_tl }
\NewEnviron { declaration } { \tl_gset:cV { g_ctuthesis_field_declaration_tl } \BODY }
\tl_new:c { g_ctuthesis_field_declaration_tl }
\tl_gset:Nn \g_ctuthesis_ctulstbg_tl { ctulstbg }
\keys_define:nn { ctuthesis } {
ctulstbg .tl_gset:N = \g_ctuthesis_ctulstbg_tl
}
% A macro called after every \keys_set{ctuthesis}{...}
\cs_new:Nn \ctuthesis_ctusetup_trigger: {
% Remove duplicates from the language list
\seq_gremove_duplicates:N \g_ctuthesis_languages_seq
% Set up titlelanguage as mainlanguage if the latter is defined and the former is not
\bool_if:nT { \tl_if_exist_p:c { g_ctuthesis_field_mainlanguage_tl }
&& ! \tl_if_empty_p:c { g_ctuthesis_field_mainlanguage_tl }
&& ( ! \tl_if_exist_p:c { g_ctuthesis_field_titlelanguage_tl }
|| \tl_if_empty_p:c { g_ctuthesis_field_titlelanguage_tl } )
} {
\keys_set:nx { ctuthesis } { titlelanguage = \tl_use:c { g_ctuthesis_field_mainlanguage_tl } }
}
% Set up secondlanguage if it has not been set up before
\bool_if:nT { \tl_if_exist_p:c { g_ctuthesis_field_mainlanguage_tl }
&& \tl_if_exist_p:c { g_ctuthesis_field_titlelanguage_tl }
&& ( ! \tl_if_exist_p:c { g_ctuthesis_field_secondlanguage_tl }
|| \tl_if_empty_p:c { g_ctuthesis_field_secondlanguage_tl } )
} {
\tl_if_eq:ccTF { g_ctuthesis_field_mainlanguage_tl } { g_ctuthesis_field_titlelanguage_tl } {
\tl_if_eq:xnTF { \tl_use:c { g_ctuthesis_field_mainlanguage_tl } } { english } {
\keys_set:nn { ctuthesis } { secondlanguage = czech }
} {
\keys_set:nn { ctuthesis } { secondlanguage = english }
}
} {
\keys_set:nx { ctuthesis } { secondlanguage = \tl_use:c { g_ctuthesis_field_mainlanguage_tl } }
}
}
}
% Key setup to be used in the preamble
\NewDocumentCommand \ctusetup { m } {
\keys_set:nn { ctuthesis } { #1 }
\ctuthesis_ctusetup_trigger:
}
%%% THEMES, TEMPLATES AND FIELDS
% Theme, template and field hadling - "unknown" error messages
\msg_new:nnn { ctuthesis } { unknown-theme } { Theme~'#1'~has~not~been~defined~
for~use~with~ \token_to_str:N \ctutheme . }
\msg_new:nnn { ctuthesis } { unknown-template } { Template~'#1'~has~not~been~defined~
for~use~with~ \token_to_str:N \ctutemplate . }
\msg_new:nnn { ctuthesis } { unknown-field } { Field~'#1'~has~not~been~defined~
for~use~with~ \token_to_str:N \ctufield . }
% Theme and template hadling - setters
\NewDocumentCommand \ctuthemeset { >{\TrimSpaces}m +m } {
\cs_set:cn { ctuthesis_theme_#1_var: } { #2 }
}
\NewDocumentCommand \ctutemplateset { >{\TrimSpaces}m +m } {
\cs_set:cn { ctuthesis_template_#1_var: } { #2 }
}
% Theme, template and field hadling - getters
\NewDocumentCommand \ctutheme { >{\TrimSpaces}m } {
\cs_if_exist_use:cF { ctuthesis_theme_#1_var: } { \msg_error:nnx { ctuthesis } { unknown-theme } { #1 } }
}
\NewDocumentCommand \ctutemplate { >{\TrimSpaces}m } {
\cs_if_exist_use:cF { ctuthesis_template_#1_var: } { \msg_error:nnx { ctuthesis } { unknown-template } { #1 } }
}
% `\ctufield` supports the context language specifier as an optional argument
\NewDocumentCommand \ctufield { >{\TrimSpaces}o >{\TrimSpaces}m } {
\IfValueTF { #1 } {
% \ctuthesis_field_exists:nF { #1 language } { \msg_error:nnx { ctuthesis } { unknown-field } { #1 } }
% \ctuthesis_field_use:n { #2_\ctuthesis_field_use:n { #1 language } }
\ctuthesis_field_use:nn { #1 } { #2 }
} {
\ctuthesis_field_use:n { #2 }
}
}
\cs_new:Nn \ctuthesis_field_use:n {
\cs_if_exist_use:cF { g_ctuthesis_field_#1_tl } { \msg_error:nnx { ctuthesis } { unknown-field } { #1 } }
}
% This one takes two arguments: the language and the field name
\cs_new:Nn \ctuthesis_field_use:nn {
\cs_if_exist:cF { g_ctuthesis_field_#1language_tl } { \msg_error:nnx { ctuthesis } { unknown-field } { #1 } }
\ctuthesis_field_use:n { #2_\ctuthesis_field_use:n { #1 language } }
}
% Theme, template and field hadling - existance conditionals
\prg_new_conditional:Nnn \ctuthesis_theme_exists:n { p, T, F, TF } {
\cs_if_exist:cTF { ctuthesis_theme_#1_var } { \prg_return_true: } { \prg_return_false: }
}
\prg_new_conditional:Nnn \ctuthesis_template_exists:n { p, T, F, TF } {
\cs_if_exist:cTF { ctuthesis_template_#1_var } { \prg_return_true: } { \prg_return_false: }
}
\prg_new_conditional:Nnn \ctuthesis_field_exists:n { p, T, F, TF } {
\cs_if_exist:cTF { g_ctuthesis_field_#1_tl } { \prg_return_true: } { \prg_return_false: }
}
% Theme, template and field hadling - publicly available conditionals with "true" and "false" branches
\DeclareDocumentCommand \ctuiftheme { s~>{\TrimSpaces}m +m +m } {
\ctuthesis_theme_exists:nTF { #2 } {
\IfBooleanTF { #1 } {
\tl_if_empty:cTF { g_ctuthesis_theme_#1_tl } { #4 } { #3 }
} {
#3
}
} {
#4
}
}
\DeclareDocumentCommand \ctuiftemplate { s~>{\TrimSpaces}m +m +m } {
\ctuthesis_template_exists:nTF { #2 } {
\IfBooleanTF { #1 } {
\tl_if_empty:cTF { g_ctuthesis_template_#1_tl } { #4 } { #3 }
} {
#3
}
} {
#4
}
}
% The starred variant checks for emptiness rather than for existance
\DeclareDocumentCommand \ctuiffield { s~>{\TrimSpaces}o >{\TrimSpaces}m +m +m } {
\IfValueTF { #2 } {
\ctuthesis_field_exists:nF { #2 language } { \msg_error:nnx { ctuthesis } { unknown-field } { #1 } }
\IfBooleanTF { #1 } {
\ctuiffield * { #3_\ctuthesis_field_use:n { #2 language } } { #4 } { #5 }
} {
\ctuiffield { #3_\ctuthesis_field_use:n { #2 language } } { #4 } { #5 }
}
} {
\ctuthesis_field_exists:nTF { #3 } {
\IfBooleanTF { #1 } {
\tl_if_empty:cTF { g_ctuthesis_field_#3_tl } { #5 } { #4 }
} {
#4
}
} {
\ctuthesis_field_exists:nTF { #3 } { #5 } { #4 }
}
}
}
% We don't do any check for existance of a switch, so better be careful.
\prg_new_conditional:Nnn \ctuthesis_if_switch:n { p, T, F, TF } {
\bool_if:cTF { g_ctuthesis_switch_#1_bool } { \prg_return_true: } { \prg_return_false: }
}
\DeclareDocumentCommand \ctuifswitch { >{\TrimSpaces}m +m +m } {
\bool_if:cTF { g_ctuthesis_switch_#1_bool } { #2 } { #3 }
}
%%% LOGGING
% Create \ctuverlog which contains the automatically updated timestamp of the file.
% It can be used for instance in \ctusetup{preprint = \ctuverlog} in order to show
% the timestamp on every page.
\cs_new:Npx \ctuverlog {
ctuthesis ~ \use_ii:nn
{2015/11/15}{ t1511151022}%MY TIMESTAMP HERE {}
}
\endinput

@ -0,0 +1,195 @@
%!TEX ROOT = ctutest.tex
\ProvidesExplFile{ctuthesis-names.def}{2014/01/18}{0.1}{"Names" part of the class ctuthesis}
% This code provides all language-dependent definitions that are needed.
% That is, no "real text" should appear anywhere else.
% We stick to the LaTeX2e syntax here for what's related directly to package `babel`
% Also, we don't use utf8, because if someone decided to switch encodings, they can,
% and we won't prevent them from doing so if we don't have to.
% General titles
\def\ctucaptionsenglish{
\def\appendicesname{Appendices}
\def\thanksname{Acknowledgements}
\def\declarationname{Declaration}
\def\listfigurename{Figures}
\def\listtablename{Tables}
\def\supervisorname{Supervisor}
\def\supervisorspecialistname{Supervisor--specialist}
\def\fieldofstudyname{Field\ of\ study}
\def\subfieldofstudyname{Subfield}
\def\specificationname{Project\ Specification}
\def\keywordsname{Keywords}
\def\titletranslationname{Title\ translation}
}
\def\ctucaptionsczech{
\def\appendicesname{P\v r\'ilohy}
\def\thanksname{Pod\v ekov\'an\'i}
\def\declarationname{Prohl\'a\v sen\'i}
\def\listfigurename{Obr\'azky}
\def\listtablename{Tabulky}
\def\supervisorname{\v Skolitel}
\def\supervisorspecialistname{\v Skolitel--specialista}
\def\fieldofstudyname{Obor}
\def\subfieldofstudyname{Zam\v e\v ren\'i}
\def\specificationname{Zad\'an\'i\ pr\'ace}
\def\keywordsname{Kl\'i \v cov\'a\ slova}
\def\titletranslationname{P\v reklad\ n\'azvu}
}
\def\ctucaptionsslovak{
\def\appendicesname{Pr\'i lohy}
\def\thanksname{Po\v dakovanie}
\def\declarationname{Prehl\'asenie}
\def\listfigurename{Obr\'azky}
\def\listtablename{Tabu\v lky}
\def\figurename{Obr\'azok}
\def\supervisorname{\v Skolite\v l}
\def\supervisorspecialistname{\v Skolite\v l--specialista}
\def\fieldofstudyname{Odbor}
\def\subfieldofstudyname{Zameranie}
\def\specificationname{Zad\'an\'i\ \ pr\'ace}
\def\keywordsname{K\v l\'u\v cov\'e\ slov\'a}
\def\titletranslationname{Preklad\ n\'azvu}
}
% Name of the university
\ctusetup{
university-endl-czech = {\v Cesk\'e\\ vysok\'e \\ u\v cen\'i ~ technick\'e \\ v ~ Praze},
university-endl-slovak = {\v Cesk\'e\\ vysok\'e \\ u\v cen\'i ~ technick\'e \\ v ~ Praze},
university-endl-english = {Czech\\ Technical \\ University \\ in ~ Prague},
university-czech = {\v Cesk\'e ~ vysok\'e ~ u\v cen\'i ~ technick\'e ~ v ~ Praze},
university-slovak = {\v Cesk\'e ~ vysok\'e ~ u\v cen\'i ~ technick\'e ~ v ~ Praze},
university-english = {Czech ~ Technical ~ University ~ in ~ Prague},
}
% Month names handling
\seq_gset_from_clist:Nn \g_ctuthesis_months_czech_seq { ledna, \'unora, b\v rezna, dubna, kv\v etna, \v cervna,
\v cervence, srpna, z\'a\v r\'i , \v r\'i jna, listopadu, prosince }
\seq_gset_from_clist:Nn \g_ctuthesis_Months_czech_seq { Leden, \'Unor, B\v rezen, Duben, Kv\v eten, \v Cerven,
\v Cervenec, Srpen, Z\'a\v r\'i , \v R\'i jen, Listopad, Prosinec }
\seq_gset_from_clist:Nn \g_ctuthesis_months_slovak_seq { janu\'ara, febru\'ara, marca, apr\'i la, m\'aja, j\'una,
j\'ula, augusta, septembera, okt\v obera, novembera, decembera }
\seq_gset_from_clist:Nn \g_ctuthesis_Months_slovak_seq { Janu\'ar, Febru\'ar, Marec, Apr\'i l, M\'aj, J\'un,
J\'ul, August, September, Okt\v ober, November, December }
\seq_gset_from_clist:Nn \g_ctuthesis_months_english_seq { January, February, March, April, May, June,
July, August, September, October, November, December }
\seq_gset_eq:NN \g_ctuthesis_Months_english_seq \g_ctuthesis_months_english_seq
\DeclareExpandableDocumentCommand \monthinlanguage { s~m } {
\IfBooleanTF { #1 } {
\seq_item:cn { g_ctuthesis_Months_\tl_use:c { g_ctuthesis_field_#2language_tl }_seq }
{ \ctuthesis_field_use:n { month } }
} {
\seq_item:cn { g_ctuthesis_months_\tl_use:c { g_ctuthesis_field_#2language_tl }_seq }
{ \ctuthesis_field_use:n { month } }
}
}
% Document types and Faculty names in all langauges
\keys_define:nn { ctuthesis } {
% Make doctype and faculty aliases for xdoctype and xfaculty
doctype .meta:n = { xdoctype = {#1} },
faculty .meta:n = { xfaculty = {#1} },
% Setup doctypes
xdoctype .meta:n = { xdoctype-#1 },
xdoctype .groups:n = { dc, nopre, nopost },
xdoctype-B .meta:n = {
doctype-english = { Bachelor ~ Project },
doctype-czech = { Bakalářská ~ práce },
doctype-slovak = { Bakalárska ~ práca }
},
xdoctype-M .meta:n = {
doctype-english = { Master ~ Thesis },
doctype-czech = { Diplomová ~ práce },
doctype-slovak = { Diplomová ~ práca }
},
xdoctype-D .meta:n = {
doctype-english = { Dissertation ~ Thesis },
doctype-czech = { Disertační ~ práce },
doctype-slovak = { Dizertačná ~ práca }
},
xfaculty .meta:n = { facultynum={#1}, xfaculty-#1, },
xfaculty-F1 .meta:n = {
faculty-english = { Faculty ~ of ~ Civil ~ Engineering },
faculty-czech = { Fakulta ~ stavební },
faculty-slovak = { Fakulta ~ stavební }
},
xfaculty-F2 .meta:n = {
faculty-english = { Faculty ~ of ~ Mechanical ~ Engineering },
faculty-czech = { Fakulta ~ strojní },
faculty-slovak = { Fakulta ~ strojní }
},
xfaculty-F3 .meta:n = {
faculty-english = { Faculty ~ of ~ Electrical ~ Engineering },
faculty-czech = { Fakulta ~ elektrotechnická },
faculty-slovak = { Fakulta ~ elektrotechnická }
},
xfaculty-F4 .meta:n = {
faculty-english = { Faculty ~ of ~ Nuclear ~ Sciences ~ and ~ Physical ~ Engineering },
faculty-czech = { Fakulta ~ jaderná ~ a ~ fyzikálně ~ inženýrská },
faculty-slovak = { Fakulta ~ jaderná ~ a ~ fyzikálně ~ inženýrská }
},
xfaculty-F5 .meta:n = {
faculty-english = { Faculty ~ of ~ Architecture },
faculty-czech = { Fakulta ~ architektury },
faculty-slovak = { Fakulta ~ architektury }
},
xfaculty-F6 .meta:n = {
faculty-english = { Faculty ~ of ~ Transportation ~ Sciences },
faculty-czech = { Fakulta ~ dopravní },
faculty-slovak = { Fakulta ~ dopravní }
},
xfaculty-F7 .meta:n = {
faculty-english = { Faculty ~ of ~ Biomedical ~ Engineering },
faculty-czech = { Fakulta ~ biomedicínského ~ inženýrství },
faculty-slovak = { Fakulta ~ biomedicínského ~ inženýrství }
},
xfaculty-F8 .meta:n = {
faculty-english = { Faculty ~ of ~ Information ~ Technology },
faculty-czech = { Fakulta ~ informačních ~ technologií },
faculty-slovak = { Fakulta ~ informačních ~ technologií }
},
xfaculty-KU .meta:n = {
faculty-english = { Klokner ~ Institute },
faculty-czech = { Kloknerův ~ ústav },
faculty-slovak = { Kloknerův ~ ústav },
facultynum = {},
},
xfaculty-CIIRC .meta:n = {
faculty-english = { Czech ~ Institute ~ of ~ Informatics, ~ Robotics ~ and ~ Cybernetics },
faculty-czech = { Český ~ institut ~ informatiky, ~ robotiky ~ a ~ kybernetiky },
faculty-slovak = { Český ~ institut ~ informatiky, ~ robotiky ~ a ~ kybernetiky },
facultynum = { CIIRC },
},
xfaculty-MUVS .meta:n = {
faculty-english = { Masaryk ~ Institute ~ of ~ Advanced ~ Studies },
faculty-czech = { Masarykův ~ ústav ~ vyšších ~ studií },
faculty-slovak = { Masarykův ~ ústav ~ vyšších ~ studií },
facultynum = { MÚVS },
},
}
\endinput

@ -0,0 +1,997 @@
%!TEX ROOT = ctutest.tex
\ProvidesExplFile{ctuth-pkg.tex}%
{2016/04/04}{0.1 t1604041107}%MY TIMESTAMP HERE {0.1}
{"Packages"\space part\space of\space the\space class\space ctuthesis}
% A lot of the code here is not latex3, but rather the good'ol latex2e code. The reason is that
% it heavily depends on l2e packages, and we decided not to mix the code together too much.
\RequirePackage{lmodern}
\RequirePackage[T1]{fontenc}
\RequirePackage{microtype}
\RequirePackage{graphicx}
\RequirePackage{pdfpages}
%%% BABEL -- LANGUAGE HANDLING
% The loading of the languages is a bit wicked, but it works this way. We load the main language once more
% to make it the default one.
\RequirePackage[\seq_use:Nn \g_ctuthesis_languages_seq {,},\g_ctuthesis_field_mainlanguage_tl]{babel}
% Used for setting title, main or second language
\NewDocumentCommand \selectctulanguage { m } {
\exp_args:Nx \selectlanguage { \ctuthesis_field_use:n { #1 language } }
}
%%% COLORS, TEXT FLOW
\RequirePackage{xcolor}
% Define the colors, first in monochrome, then in colour.
\ctuifswitch { savetoner } {
% savetoner: true
\definecolor { ctublue } { CMYK } { 100, 43, 0, 0 }
\definecolor { ctulightblue } { RGB }{ 172, 214, 238 }
\colorlet { ctubluetext } { ctublue }
\colorlet { ctubluerule } { ctulightblue }
\colorlet { ctubluedarkbg } { white }
\colorlet { ctubluedarkfg } { ctublue!50!black }
\colorlet { ctubluedot } { white }%ctulightblue }
\colorlet { ctubluebg } { white }
\colorlet { ctulstbg } { ctubluebg }
\colorlet { ctublueitemi } { ctublue }
\colorlet { ctublueitemii } { ctulightblue }
\colorlet { ctugray } { gray }
\definecolor { ctuorange } { Hsb } { 22, 0.5, 1 }
} {
\ctuifswitch { monochrome } {
% savetoner: false, monochrome: true
\definecolor { ctublue } { gray } { 0.8 }
\definecolor { ctulightblue } { gray } { 0.9 }
\definecolor { ctubluetext } { gray } { 0.4 }
\definecolor { ctubluerule } { gray } { 0.4 }
\definecolor { ctubluedarkbg } { gray } { 0.2 }
\definecolor { ctubluedarkfg } { gray } { 1 }
\definecolor { ctubluedot } { gray } { 0.9 }
\definecolor { ctubluebg } { gray } { 0.95 }
\definecolor { ctulstbg } { gray } { 0.95 }
\definecolor { ctublueitemi } { gray } { 0.4 }
\definecolor { ctublueitemii } { gray } { 0.4 }
\definecolor { ctugray } { gray } { 0.5 }
\definecolor { ctuorange } { gray } { 0.9 }
} {
% savetoner: false, monochrome: false
\definecolor { ctublue } { cmyk } { 1, .43, 0, 0 }
\definecolor { ctulightblue } { cmyk }{ .3, .13, 0, 0 }
\colorlet { ctubluetext } { ctublue }
\colorlet { ctubluerule } { ctublue }
\colorlet { ctubluedarkbg } { ctublue }
\colorlet { ctubluedot } { ctulightblue }
\colorlet { ctubluebg } { ctulightblue!50!white }
\colorlet { ctulstbg } { ctulightblue!50!white }
\colorlet { ctublueitemi } { ctublue }
\colorlet { ctublueitemii } { ctulightblue }
\colorlet { ctugray } { gray }
\definecolor { ctuorange } { cmyk } { 0, .51, 1, 0 }
}
}
\setlength{\parskip}{0pt plus 1pt}
\setlength{\parindent}{11.2pt}
%%% FRONT MATTER --- TWOCOLUMN HANDLING
% This is a "ToC macro" for the twocolumn context
% Arguments: 1) suffix, 2) ToC name
\cs_new:Nn \ctuthesis_maketoc_twocol:nn {
% Start the chapter
\chapter* { #2 }
% locally make rugged pages
\begingroup
\raggedbottom
% We use this trick to add nothing, but also to make sure that
% any \addvspace for less than 20pt is going to be ignored.
\vspace*{-20pt}\addvspace{20pt}
% call the original \@starttoc
\@starttoc { #1 }
\newpage
\endgroup
}
% Environment for the twocolumn frontmatter. It can appear more times in a row
% and should handle it nicely
\NewDocumentEnvironment{ twocolumnfrontmatterpage } { } {
% Set the page geometry to the title one (it's a bit wider)
\ctuthesis_geometry_title:
\newpage
\pagestyle{twocol}
\onecolumn\relax %ADDED (??)
% Start the twocolumn.
% \twocolumn[]\relax
% We are narrow, so we wanna be sloppy
% \sloppy % CHANGED REMOVED
% Chapter behaves differently. Both the [] argument and the star * are ignored.
% \DeclareDocumentCommand\chapter{ s o m }{\relax
% % Vertical adjustment
% \vspace* { -\baselineskip }
% \nointerlineskip
% % Zero measure vertical box, the contents are raised by something and typeset
% \vbox to 0pt{\noindent\leavevmode\smash{\raise6pt\hbox to \linewidth{%
% % In the first column its right-aligned, in the second left-aligned.
% % It can't be more than one line.
% \if@firstcolumn\hfil\fi
% \color{ctubluetext}\LARGE\bfseries\sffamily##3
% \if@firstcolumn\else\hfil\fi
% }}}
% \everypar{\noindent}
% }
\DeclareDocumentCommand\chapter{ s~o~m }{\relax
% Compute the vertical adjustment
\skip_gset:Nn \g_ctuthesis_tempa_skip { - \box_ht:N \strutbox }
{ \LARGE \skip_gsub:Nn \g_ctuthesis_tempa_skip { \box_ht:N \strutbox + \box_dp:N \strutbox } }
% Space used if not at the beginning of a column
\skip_vertical:n { 12pt - \g_ctuthesis_tempa_skip }
% Add the space below the chapter title to the adjustment
\skip_gsub:Nn \g_ctuthesis_tempa_skip { 2pt }
% Vertical adjustment
\vspace* { \g_ctuthesis_tempa_skip }
% Zero measure vertical box, the contents are raised by something and typeset
\noindent \leavevmode
\hbox_to_wd:nn \linewidth {
% In the first column its right-aligned, in the second left-aligned.
% It can't be more than one line.
%\if@firstcolumn\hfil\fi
\leavevmode\color{ctubluetext}\LARGE\strut\bfseries\sffamily##3
%\if@firstcolumn\else\hfil\fi
}\par
\skip_vertical:n { 2pt }
\everypar{\noindent}
}
\DeclareDocumentCommand \tableofcontents { }{ \ctuthesis_maketoc_twocol:nn { toc } { \contentsname } }
\DeclareDocumentCommand \listoffigures { }{ \ctuthesis_maketoc_twocol:nn { lof } { \listfigurename } }
\DeclareDocumentCommand \listoftables { }{ \ctuthesis_maketoc_twocol:nn { lot } { \listtablename } }
} {
\ctuthesis_geometry_plain:
\clearpage
\onecolumn
\pagestyle{plain}
}
%%% LANGUAGES
% For every of the languages below, if it's initialized, add the
% custom captions of the class
\@ifundefined{captionsenglish}{}{\g@addto@macro\captionsenglish{\ctucaptionsenglish}}
\@ifundefined{captionsczech}{}{\g@addto@macro\captionsczech{\ctucaptionsczech}}
\@ifundefined{captionsslovak}{}{\g@addto@macro\captionsslovak{\ctucaptionsslovak}}
%%% GEOMETRY
% The ratios of inner:outer margins
% Needs to be separate as this to make the colon ":" have the right catcode
\cs_new:Nx \ctuthesis_geometry_hmarginratio: {2\string :3} %4\string :6
% Target textwidth is 33*basesize (10pt to 12pt)
\dim_const:Nn \g_ctuthesis_geometry_textwidth_dim { \tl_use:N \g_ctuthesis_fontsize_tl * 39 } %33
% Text occupies 75% of the height of the page by default, less if layout-short is active
% The vmargin ratio is set here in the same manner as the hmargin one above
\ctuifswitch { layout-short } {
\dim_const:Nn \g_ctuthesis_geometry_textheight_dim { 1.5\g_ctuthesis_geometry_textwidth_dim }
\cs_new:Nx \ctuthesis_geometry_vmarginratio: {4\string :3}
} {
\dim_const:Nn \g_ctuthesis_geometry_textheight_dim { 0.75\paperheight }
\cs_new:Nx \ctuthesis_geometry_vmarginratio: {5\string :6}
}
% Loading the geometry package.
% Almost the same setting appears again in \ctuthesis_geometry_plain:
\RequirePackage [ a4paper ,
hmarginratio = \ctuthesis_geometry_hmarginratio: ,
textwidth = \g_ctuthesis_geometry_textwidth_dim ,
textheight = \g_ctuthesis_geometry_textheight_dim ,
vmarginratio = \ctuthesis_geometry_vmarginratio: , ignoreheadfoot ,
% Should be at least \baselineskip
headheight = 16pt ,
marginparsep = 10pt ,
] { geometry }
% Inner margin is 1in + \oddsidemargin. We wanna preserve this value through all
% the different page geometries
\dim_const:Nn \g_ctuthesis_geometry_innermargin_dim { 1in + \the\oddsidemargin }
% The frontmatter pages are a bit wider
\cs_new:Nn \ctuthesis_geometry_title: {
\newgeometry {
% Use the stored innermargin value
inner = \g_ctuthesis_geometry_innermargin_dim ,
% Increase the width by 20%, but do not exceed 420pt
textwidth = \dim_min:nn { 420pt } { 1.2 \g_ctuthesis_geometry_textwidth_dim } ,
textheight = \g_ctuthesis_geometry_textheight_dim ,
vmarginratio = \ctuthesis_geometry_vmarginratio: ,
headheight = 16pt ,
ignoreheadfoot ,
columnsep=30pt ,
}
}
\cs_new:Nn \ctuthesis_geometry_plain: {
\newgeometry {
% Use the stored innermargin value
inner = \dim_use:N \g_ctuthesis_geometry_innermargin_dim ,
% Otherwise it's the same as in \RequirePackage[...]{geometry}
textwidth = \dim_use:N \g_ctuthesis_geometry_textwidth_dim ,
textheight = \g_ctuthesis_geometry_textheight_dim ,
vmarginratio = \ctuthesis_geometry_vmarginratio: , ignoreheadfoot ,
headheight = 16pt ,
marginparsep = 10pt ,
}
% Compute the marginparwidth so that we leave 40pt from the page boundary
\marginparwidth \dimexpr \evensidemargin + 1in - \marginparsep - 40pt
}
% Re-initialize the geometry
\ctuthesis_geometry_plain:
%%% TITLES
\usepackage{titlesec}
% two basic parameters: the rule width and distance
\newlength \ctu@title@rulewidth
\newlength \ctu@title@rulesep
\setlength \ctu@title@rulewidth {11pt}
\setlength \ctu@title@rulesep {11pt}
% box used all the time
\newbox\ctu@title@box
% macro that boxifies the header and adds the rule
\long\def\ctu@title@boxify#1#2#3#4{
\sffamily
\bfseries
\setbox\ctu@title@box\vbox{\hsize\dimexpr\linewidth-\ctu@title@rulewidth-\ctu@title@rulesep\relax
\vskip#1
\raggedright
#3
\vskip#2
}
#4
\noindent\begin{tabular}{@{}l@{\hspace*{\ctu@title@rulesep}}l@{}}
\color{ctubluerule}\rule[-\dp\ctu@title@box]{\ctu@title@rulewidth}{\dimexpr\ht\ctu@title@box+\dp\ctu@title@box}
&
\box\ctu@title@box
\end{tabular}\hspace*{-10pt}
\par
}
\long\def\ctu@title@boxify@x#1#2#3#4#5{
\sffamily
\bfseries
\setbox\ctu@title@box\vbox{\parskip0pt\hsize\dimexpr\linewidth-\ctu@title@rulewidth-\ctu@title@rulesep\relax
\vskip#1
\raggedright
#4
\vskip#2
}
#5
\noindent\begin{tabular}{@{}l@{\hspace*{\ctu@title@rulesep}}l@{}}
\color{ctubluerule}
\rule
[\dimexpr\ht\ctu@title@box-#3-#1]
{\ctu@title@rulewidth}
{\dimexpr#1+#3}
&
\box\ctu@title@box
\end{tabular}\hspace*{-10pt}
\par
}
% the part style, very simply organized
\def\ttlh@ctupt#1#2#3#4#5#6#7#8{
\bool_gset_true:N \g_ctuthesis_title_haspart_bool
\ctu@title@boxify{#5}{#3}{
{#1\strut\ifttl@label#2\fi\par}
\vskip30pt
{\color{ctubluetext}#4\strut#8\strut\par}
}{\dp\ctu@title@box\dimexpr\textheight-\ht\ctu@title@box-\baselineskip\relax
}
}
\def\ttlh@ctuch#1#2#3#4#5#6#7#8{
\vspace{-\parskip}
% If the chapter is starred, we still want to \chaptermark it, just we use the variant \chapterstarmark.
\ifttl@label\else\chapterstarmark{#8}\fi
% If the chapter is starred, we still want it in the ToC.
\ifttl@label\else\addcontentsline{toc}{chapter}{#8}\fi
\ctu@title@boxify{#5}{#3}{
{#1\strut\ifttl@label#2\fi\par}
\medskip
{\color{ctubluetext}#4\strut#8\strut\par}
}{}
}
% The section style, very simply organized, subsection style differs only by a missing check for star variant and mark inclusion
% Comments to the chapter style apply here too.
\def\ttlh@ctus#1#2#3#4#5#6#7#8{
\vspace{-.2em}
\ifttl@label\else\sectionstarmark{#8}\fi
\ifttl@label\else\addcontentsline{toc}{section}{#8}\fi
\ctu@title@boxify@x{#5}{0pt}{#3}{ \vspace{-1pt} #1{\ifttl@label#2\fi\strut\color{ctubluetext}#8\strut} }{}
\par\nobreak
\vspace{-.5em}
}
\def\ttlh@ctuss#1#2#3#4#5#6#7#8{
\vspace{-.2em}
\ifttl@label\else\addcontentsline{toc}{subsection}{#8}\fi
\ctu@title@boxify@x{#5}{0pt}{#3}{ #1{\ifttl@label#2\fi\strut\color{ctubluetext}#8\strut} }{}
\par\nobreak
\vspace{-.5em}
}
\def\ttlh@ctusss#1#2#3#4#5#6#7#8{
\vspace{-.2em}
\ifttl@label\else\addcontentsline{toc}{subsubsection}{#8}\fi
\ctu@title@boxify@x{#5}{0pt}{#3}{ \vspace{-1pt} #1{\ifttl@label#2\fi\strut\color{ctubluetext}#8\strut} }{}
\par\nobreak
\vspace{-.5em}
}
% Modified \ttl@page@ii to use \cleardoublepage instead of some idiocy
\def\ttl@page@ii#1#2#3#4#5#6#7{%
\ttl@assign\@tempskipa#3\relax\beforetitleunit
\if@openright
\cleardoublepage
\else
\clearpage
\fi
\@ifundefined{ttl@ps@#6}%
{\thispagestyle{plain}}%
{\thispagestyle{\@nameuse{ttl@ps@#6}}}%
\if@twocolumn
\onecolumn
\@tempswatrue
\else
\@tempswafalse
\fi
\vspace*{\@tempskipa}%
\@afterindenttrue
\ifcase#5 \@afterindentfalse\fi
\ttl@assign\@tempskipb#4\relax\aftertitleunit
\ttl@select{#6}{#1}{#2}{#7}%
\ttl@finmarks
\@ifundefined{ttlp@#6}{}{\ttlp@write{#6}}%
\vspace{\@tempskipb}%
\cleardoublepage
\if@tempswa
\twocolumn
\fi
\ignorespaces}
% Part title setting
\bool_new:N \g_ctuthesis_title_haspart_bool
\titleformat \part [ctupt] {\Huge} {{\huge\partname\nobreakspace}\thepart} {0pt} {\huge} [0.6\textheight]
\titlespacing* \part {0pt} {0pt} {0pt}
% Tweak into titlesec to make part number contain \numberline. They did not include it for some reason.
\def\ttl@tocpart{\def\ttl@a{\protect\numberline{\thepart}}}
% Chapter title setting
\titleformat \chapter [ctuch] {\huge} {{\LARGE\chaptertitlename\ }\thechapter} {-0\dp\strutbox} {\LARGE} [40pt]
\titlespacing* \chapter {0pt} {0pt} {15pt} % CHANGED was {0pt} {40pt} {15pt}
% Section title setting
\titleformat \section [ctus] {\Large} {\thesection\quad} {14pt} {} [2pt]
\titleformat \subsection [ctuss] {\large} {\thesubsection\quad} {11pt} {} [0pt]
\titleformat \subsubsection [ctusss] {\normalsize} {\thesubsubsection\quad} {10pt} {} [0pt]
% Paragraph title setting: runin, with a dot.
\cs_new:Nn \ctuthesis_title_adddot:n {#1\@addpunct.\ignorespaces}
\titleformat \paragraph [runin] {\normalfont\normalsize\bfseries\sffamily} {\theparagraph} {1em} {\ctuthesis_title_adddot:n}
\titleformat \subparagraph [runin] {\normalfont\normalsize\itshape} {\thesubparagraph} {1em} {\ctuthesis_title_adddot:n}
\titlespacing* \paragraph {0pt} {2.25ex plus 1ex minus .2ex} {1em plus 0.3em minus 0.2em}
\titlespacing* \subparagraph {\parindent} {1.75ex plus 0.5ex minus .2ex} {0.7em plus 0.3em minus 0.15em}
% Subsections are the lowest numbered titles, and also the lowest included in ToC.
\setcounter{secnumdepth}{2}
\setcounter{tocdepth}{2}
% Appendix treatment: Even if a chapter in appendix has a star, it will get a number (letter in this case), since
% once you get any appendix, it doesn't make sense not to number some of them.
% Users can use \chapter** if-need-be to get an unnumbered chapter in appendix, but we think it's ridiculous.
\cs_set_eq:NN \ctuthesis_title_orig_appendix: \appendix
\cs_set_eq:NN \ctuthesis_title_orig_chapter: \chapter
\cs_set_eq:NN \ctuthesis_title_orig_makeschapterhead: \@makeschapterhead
% an \if that is true only after \appendix
\newif\ifctu@app \ctu@appfalse
% The new \appendix
\DeclareDocumentCommand \appendix { s~s~} {
\ctu@apptrue
% Call the old \appendix
\ctuthesis_title_orig_appendix:
% If the document has \part division, let's make "Appendices" a part on their own
\bool_if:NT \g_ctuthesis_title_haspart_bool {
% But only make the notice in ToC if * is used
\IfBooleanTF { #2 } {
% Two stars: If nothing in ToC, at least put there a space.
\addtocontents{toc}{\vskip 2ex plus 0.2pt}
} {
\IfBooleanTF { #1 } {
% One star: Only add "Appendices" in ToC
\cleardoublepage
\addcontentsline { toc } { part } { \appendicesname }
} {
% Zero stars: Make "Appendices" page (will be in ToC implicitly
\part*{ \appendicesname }
}
}
}
% \chapter ignores one star, so that things like {thebibliography} are numbered
\DeclareDocumentCommand \chapter { s~} { \ctuthesis_title_orig_chapter: }
% another \appendix will generate a warning and be silently ignored
\DeclareDocumentCommand \appendix { s~s~} {
\msg_warning:nn { ctuthesis } { appendix-twice }
}
}
\msg_new:nnn { ctuthesis } { appendix-twice } { The~macro~ \token_to_str:N \appendix\ should~
be~used~only~once.~Silently~ignoring. }
%%% TABLE OF CONTENTS, LISTS OF FIGURES AND TABLES
% Right margin in TOC, note that it need not be wider than the page numbers, so we're fine with 1em.
\def\@tocrmarg{1em}
% New dottedtocline, differs from the default by having numberline variable-width and accomodating to the number
\def\ctu@dottedtocline#1#2#3#4#5{\ifnum #1>\c@tocdepth \else
\addvspace{0pt plus .2pt}
{
\leftskip #2\relax
\rightskip\dimexpr\@tocrmarg plus 1fil
\parfillskip -\rightskip
\parindent #3\relax
\@afterindenttrue
\interlinepenalty\@M
\leavevmode
\null
\nobreak
\hskip -\leftskip
\def\numberline##1{##1\ }
{#4}
\nobreak
\leaders \hbox {$\m@th \mkern 2mu\hbox {.}\mkern 2mu$}\hfill
\nobreak
{\kern0.5em#5}
\par
}
\fi}
% Part in ToC: centered, with no pagenumber, bf sf, and with nice space above.
\def\l@part#1#2{
\addvspace{2ex plus .2pt}
{
\centering
\@afterindenttrue
\interlinepenalty\@M
\leavevmode
\null
\nobreak
\def\numberline##1{\partname \nobreakspace ##1\\}%
\sffamily \bfseries
#1
\par
}\penalty10000\relax
}
% Chapter in ToC: bf sf, no leaders, completely left-aligned, the numberline is variable-width,
% nice space above the chapter line
\def\l@chapter#1#2{
\addvspace{1ex plus .2pt}
{
\raggedright
\rightskip\dimexpr\@tocrmarg plus 1fil
\parfillskip -\rightskip
\@afterindenttrue
\interlinepenalty\@M
\leavevmode
\null
\nobreak
\def\numberline##1{##1\hspace*{0.5em}}
\sffamily \bfseries
#1
\nobreak
\hfill
\nobreak
{\kern0.5em#2}
\par
}\penalty9999\relax
}
% The section and lower in Toc. We hope nobody would put `\paragraph`s in ToC
\def\l@section{\ctu@dottedtocline{1}{0.6em}{0em}}
\def\l@subsection{\ctu@dottedtocline{2}{1.2em}{1.2em}}
\def\l@subsubsection{\ctu@dottedtocline{3}{1.8em}{2.4em}}
% Figures and tables in LoF and LoT exactly as sections, just the level is set to -2 so that they're always shown
\def\l@figure{\ctu@dottedtocline{-2}{0.6em}{0em}}
\let\l@table\l@figure
%%% FANCY HEADERS
\RequirePackage{fancyhdr}
% Spacial pagestyle for twocolumnpages in the frontmatter: includes centered pagenumber in the bottom
% and we abuse \fancyhead[C] to include the dividing rule
\fancypagestyle{twocol}{
\fancyhf { }
\fancyfoot [ RO, LE ] { \texttt { \ctufield { preprint } } }
\fancyfoot [ C ] { \thepage }
% CHANGED removed the blue rule
% \fancyhead [ C ] {
% \leavevmode
% \smash {
% \color{ctubluerule}
% \rule [ \dimexpr - \textheight - \headsep - 6pt ]{ 11pt }{ \textheight }
% }
% }
\renewcommand { \headrulewidth } { 0pt }
\renewcommand { \footrulewidth } { 0pt }
\dim_set_eq:NN \headwidth \textwidth
}
\fancypagestyle { cleardoublepage } {
% On \cleardoublepage (without star), we want the page number, but nothing else,
% that is, the same as plain pagestyle
\ps@plain
}
% Plain pagestyle for chapter and part titles: no rules, just the page number
\fancypagestyle { plain } {
\fancyhf { }
\fancyfoot [ RO, LE ] { \texttt { \ctufield { preprint } } }
\fancyfoot [ C ] { \thepage }
\renewcommand \headrulewidth { 0pt }
\renewcommand \footrulewidth { 0pt }
% reset headwidth to the global textwidth
\dim_set_eq:NN \headwidth \g_ctuthesis_geometry_textwidth_dim
}
% Headings pagestyle for standard text pages
\fancypagestyle { headings } {
% Copy the plain pagestyle
\ps@plain
% Include the left/rightmark and leaders
\fancyhead [ LE ] { \ctuthesis_fancy_xlap:nn { right } { \leftmark \ctuthesis_fancy_leaders:n { l } } }
\fancyhead [ RO ] { \ctuthesis_fancy_xlap:nn { left } { \ctuthesis_fancy_leaders:n { r } \rightmark } }
}
% The leaders macro for the fancyhead: nice little boxes. We make three of them: left, right and center-aligned
\box_new:N \g_ctuthesis_fancy_bluerule_l_box
\hbox_set_to_wd:Nnn \g_ctuthesis_fancy_bluerule_l_box { 10.5pt } {
{ \color{ctubluedot} \smash{\fontsize{28.88}{0}\fontfamily{lmss}\bfseries.} }
\hfil
}
\box_new:N \g_ctuthesis_fancy_bluerule_r_box
\hbox_set_to_wd:Nnn \g_ctuthesis_fancy_bluerule_r_box { 10.5pt } {
\hfil
{ \color{ctubluedot} \smash{\fontsize{28.88}{0}\fontfamily{lmss}\bfseries.} }
}
\box_new:N \g_ctuthesis_fancy_bluerule_c_box
\hbox_set_to_wd:Nnn \g_ctuthesis_fancy_bluerule_c_box { 10.5pt } {
\hfil
{ \color{ctubluedot} \smash{\fontsize{28.88}{0}\fontfamily{lmss}\bfseries.} }
\hfil
}
% The leaders macro for the fancyhead: nice little boxes,
% the parameter #1 chooses one of the boxes above
\cs_new:Nn \ctuthesis_fancy_leaders:n {
\hspace*{-1pt}
\leaders \box_use:c {g_ctuthesis_fancy_bluerule_#1_box} \hfill
\hspace*{-1pt}
}
% This macro works as follows: The width of the material is actually zero. We use \hbox_overlap_left/right
% to make the headers as wide as we wish, the direction is in #1. In #2 is the contents, and we suppose
% that it contains \ctuthesis_fancy_leaders: and \left/rightmark in desired order; it's typeset gray sf it
\cs_new:Nn \ctuthesis_fancy_xlap:nn {
\color{ctugray} \sffamily\itshape
\leavevmode \use:c { hbox_overlap_#1:n } {
\hbox_to_wd:nn { \paperwidth - 1in - \evensidemargin + 1em } { #2 }
}
}
% We rename the original \mark... commands and disable them; we do it ourselves
\cs_set_eq:NN \ctuthesis_fancy_markboth_orig:nn \markboth
\cs_set_eq:NN \ctuthesis_fancy_markright_orig:n \markright
\let\markboth\@gobbletwo
\let\markright\@gobble
% New chapter and section marks with no \MakeUppercase
\renewcommand \chaptermark [1] { \ctuthesis_fancy_markboth_orig:nn { \thechapter.\ #1 }{ \thechapter.\ #1 } }
\renewcommand \sectionmark [1] { \ctuthesis_fancy_markright_orig:n { \thesection.\ #1 } }
% Newly defined \chapter/sectionstarmark to be used with unnumbered chapters and sections.
% Not that we like unnumbered ones, but if they need to be there, they sould be in headings, too.
\newcommand \chapterstarmark [1] { \ctuthesis_fancy_markboth_orig:nn { #1 } { #1 } }
\newcommand \sectionstarmark [1] { \ctuthesis_fancy_markright_orig:n { #1 } }
% Better \cleardoublepage that takes proper treatment of the empty pages.
% The starred variant leaves the empty page inbetween really completely empty
\DeclareDocumentCommand \cleardoublepage { s~} {
\clearpage
\if@twoside\ifodd\c@page\else
% \IfBooleanTF { #1 } {
% Starred variant: completely empty page
\leavevmode
\thispagestyle{empty}
% } {
% Non-starred variant: include page number
\leavevmode
\thispagestyle{cleardoublepage}
% }
\newpage
% In twocolumn, we need \newpage twice
\if@twocolumn\hbox{}\newpage\fi
\fi\fi
}
%%% FLOATS
\usepackage{float,caption}
% default placement of all floats is `t`
\floatplacement{figure}{t}
\floatplacement{table}{t}
\floatplacement{figure*}{t}
\floatplacement{table*}{t}
% minimum 70% of page height on float pages
\renewcommand{\floatpagefraction}{0.7}
% 2 floats on top, no on bottom
\setcounter{topnumber}{2}
\setcounter{bottomnumber}{0}
\setcounter{totalnumber}{4}
% up to 90% of floats on a mixed page, at least 7% of text
\renewcommand{\topfraction}{0.7}
\renewcommand{\bottomfraction}{0.7}
\renewcommand{\textfraction}{0.2}
% float caption: justification with extra margins on both sides
\DeclareCaptionJustification{myjustify}{\leftskip.8em \rightskip.8em \parfillskip.8em plus 1fil}
% float caption: special format
\DeclareCaptionFormat{myformat}{%
% float name bf sf
\begingroup\sffamily\bfseries#1#2:~\endgroup
% float caption normal font
\begingroup#3\par\endgroup
}
\DeclareCaptionFormat{mysubformat}{%
% float name small caps
#1#2 %
% float caption normal font
\begingroup#3\par\endgroup
}
% plain float style is what we like, with captions at the bottom
\floatstyle{plain}
% restyle already existing floats
\restylefloat{figure}
\restylefloat{table}
% set up the captions: no indent of captions, no seperator (seperator is handled by {myformat})
\captionsetup{format=myformat,indent=0pt,labelsep=none,justification=myjustify,font={small},position=below}
% float-caption distance
\abovecaptionskip 8pt plus 3pt minus 1pt
% graphics allowed: pdf, png, jpg
\DeclareGraphicsExtensions{.pdf,.png,.jpg}
% floats should be centered by default:
\g@addto@macro{\@floatboxreset}{\centering}
% nice table rules
\usepackage{booktabs}
\newcommand \Midrule { \midrule[\heavyrulewidth] }
% colored tables
\newenvironment{ctucolortab}{\begin{lrbox}{0}}{\end{lrbox}\ht0\dimexpr\ht0 + 2pt\relax{\fboxsep0pt\colorbox{ctubluebg}{\usebox{0}}}}
\newenvironment{ctucolortab*}{\begin{lrbox}{0}}{\end{lrbox}{\fboxsep0pt\colorbox{ctubluebg}{\usebox{0}}}}
%%% LISTS
% Temp box
\box_new:N \g_ctuthesis_tempa_box
% Macro used to generate the itemize labels
% parameters 1:depth, 2: raise (without ex), 3: scale, 4:color
\cs_new:Nn \ctuthesis_list_prepare_labelitem:nnnn {
% Each label stored in a box
\box_new:c { g_ctuthesis_list_label_#1_box }
% use the temp box to measure the symbol
\hbox_gset:Nn \g_ctuthesis_tempa_box {
\scalebox{#3}{\fontfamily{lmss}\bfseries\color{#4}.}
}
% The label is actually a shifted up, scaled, coloured lmss bf dot
\hbox_gset:cn { g_ctuthesis_list_label_#1_box } {
\box_move_up:nn { #2 ex } \hbox_to_wd:nn {
\box_ht:N \g_ctuthesis_tempa_box
} {
\hss
\scalebox{#3}{\fontfamily{lmss}\bfseries\color{#4}.}
\hss
}
}
\cs_set:cpn { labelitem #1 } { \box_use:c { g_ctuthesis_list_label_#1_box } }
}
% The four labels for itemize
\ctuthesis_list_prepare_labelitem:nnnn { i~