diff --git a/.github/ISSUE_TEMPLATE/exercise.md b/.github/ISSUE_TEMPLATE/exercise.md deleted file mode 100644 index a9a776b7..00000000 --- a/.github/ISSUE_TEMPLATE/exercise.md +++ /dev/null @@ -1,27 +0,0 @@ ---- -name: Exercise -about: Create a report to help us improve -title: '' -labels: fixme -assignees: '' - ---- - -* Day: xx -* Exercise: xx - -A clear and concise description of what the problem/misunderstanding is. - -**Examples** -If applicable, add examples to help explain your problem. - -```python -print("Code example") -``` - -**Screenshots** -If applicable, add screenshots to help explain your problem. - -## Fixed on: -- [ ] Github -- [ ] Gitlab diff --git a/.github/ISSUE_TEMPLATE/updates-post-testing.md b/.github/ISSUE_TEMPLATE/updates-post-testing.md deleted file mode 100644 index e6a540d0..00000000 --- a/.github/ISSUE_TEMPLATE/updates-post-testing.md +++ /dev/null @@ -1,41 +0,0 @@ ---- -name: Updates post-testing -about: Updates post-testing for a whole day -title: Dayxx - Updates post-testing -labels: fixme -assignees: '' - ---- - -## Global notes: - -- [ ] 1. -- [ ] 2. - -### ex00: -- [ ] 1. -- [ ] 2. - -### ex01: -- [ ] 1. -- [ ] 2. - -### ex02: -- [ ] 1. -- [ ] 2. - -### ex03: -- [ ] 1. -- [ ] 2. - -### ex04: -- [ ] 1. -- [ ] 2. - -### ex05: -- [ ] 1. -- [ ] 2. - -### ex06: -- [ ] 1. -- [ ] 2. diff --git a/.github/workflows/README.md b/.github/workflows/README.md new file mode 100644 index 00000000..12363e1e --- /dev/null +++ b/.github/workflows/README.md @@ -0,0 +1,15 @@ +# About 42AI actions + +## make-it.yml + +> On any push, regardless of the branch, this action will attempt to build the PDFs. + +## release-it.yml + +> Branch : MASTER + +For any push on MASTER branch, this action will build the PDFs and publish a new release for the project. + +> NB: For the new release to appear, uploaded code must contain a non-existing VERSION. +> Adapt the content of the file `/version` accordingly. + diff --git a/.github/workflows/latex-builder.yml b/.github/workflows/latex-builder.yml deleted file mode 100644 index f8a8835b..00000000 --- a/.github/workflows/latex-builder.yml +++ /dev/null @@ -1,110 +0,0 @@ -name: Latex Builder - -on: [push] - -jobs: - make-it: - runs-on: ubuntu-latest - container: - image: blang/latex:ubuntu - steps: - - name: checkout repo - uses: actions/checkout@v2 - - name: version - run: echo "::set-output name=version::$(cat version)" - id: version - - name: Make pdf - run: | - make - cp build/module00.pdf / - cp build/module01.pdf / - cp build/module02.pdf / - cp build/module03.pdf / - cp build/module04.pdf / - - name: Upload pdf artifacts - uses: actions/upload-artifact@v2 - with: - name: modules.pdf - path: | - /module00.pdf - /module01.pdf - /module02.pdf - /module03.pdf - /module04.pdf - - release-it: - runs-on: ubuntu-latest - container: - image: blang/latex:ubuntu - if: "contains(github.ref, 'master')" - steps: - - name: checkout repo - uses: actions/checkout@v2 - - name: version - run: echo "::set-output name=version::$(cat version)" - id: version - - name: Make pdf - run: | - make - cp build/module00.pdf / - cp build/module01.pdf / - cp build/module02.pdf / - cp build/module03.pdf / - cp build/module04.pdf / - cp CHANGELOG.md / - - name: create release - uses: actions/create-release@v1 - id: create_release - with: - draft: false - prerelease: false - release_name: release_${{ steps.version.outputs.version }} - tag_name: version/${{ steps.version.outputs.version }} - body_path: /CHANGELOG.md - env: - GITHUB_TOKEN: ${{ github.token }} - - name: Release Module00 - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ github.token }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: /module00.pdf - asset_name: module00.pdf - asset_content_type: application/pdf - - name: Release Module01 - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ github.token }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: /module01.pdf - asset_name: module01.pdf - asset_content_type: application/pdf - - name: Release Module02 - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ github.token }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: /module02.pdf - asset_name: module02.pdf - asset_content_type: application/pdf - - name: Release Module03 - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ github.token }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: /module03.pdf - asset_name: module03.pdf - asset_content_type: application/pdf - - name: Release Module04 - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ github.token }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: /module04.pdf - asset_name: module04.pdf - asset_content_type: application/pdf \ No newline at end of file diff --git a/.github/workflows/make-it.yml b/.github/workflows/make-it.yml new file mode 100644 index 00000000..e6e62405 --- /dev/null +++ b/.github/workflows/make-it.yml @@ -0,0 +1,32 @@ +name: make-it + +on: [push] + +jobs: + make-it: + permissions: + contents: write + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Install LaTex utilities + run: sudo apt update && sudo apt-get install -y texlive-full + - name: Get version from file + id: get_version + run: echo "VERSION=version/$(cat version)" >> $GITHUB_ENV + - name: Name release from version + id: get_release + run: echo "RELEASE=release_$(cat version)" >> $GITHUB_ENV + - name: Build PDFs + run: make + - name: Upload PDFs archives + uses: actions/upload-artifact@v4 + with: + name: modules.pdf + path: | + build/module00.pdf + build/module01.pdf + build/module02.pdf + build/module03.pdf + build/module04.pdf \ No newline at end of file diff --git a/.github/workflows/release-it.yml b/.github/workflows/release-it.yml new file mode 100644 index 00000000..d8de0e43 --- /dev/null +++ b/.github/workflows/release-it.yml @@ -0,0 +1,46 @@ +name: release-it + +on: [push] + +jobs: + release-it: + permissions: + contents: write + runs-on: ubuntu-latest + if: contains(github.ref, 'master') + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Install LaTex utilities + run: sudo apt update && sudo apt-get install -y texlive-full + - name: Get version from file + id: get_version + run: echo "VERSION=version/$(cat version)" >> $GITHUB_ENV + - name: Name release from version + id: get_release + run: echo "RELEASE=release_$(cat version)" >> $GITHUB_ENV + - name: Build PDFs + run: make + - name: Upload PDFs archives + uses: actions/upload-artifact@v4 + with: + name: modules.pdf + path: | + build/module00.pdf + build/module01.pdf + build/module02.pdf + build/module03.pdf + build/module04.pdf + - name: Bundle Release + uses: softprops/action-gh-release@v2 + with: + files: | + build/module00.pdf + build/module01.pdf + build/module02.pdf + build/module03.pdf + build/module04.pdf + name: ${{env.RELEASE}} + tag_name: ${{env.VERSION}} + make_latest: true + body_path: CHANGELOG.md \ No newline at end of file diff --git a/.gitignore b/.gitignore index 6ace9fc9..6254f945 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,9 @@ # Personnal *.zip +# VSCode +*.vscode/ + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] @@ -9,6 +12,11 @@ __pycache__/ # C extensions *.so +# Latex compilation files +*.fdb_latexmk +*.fls +*.pdf.version + # Distribution / packaging .Python develop-eggs/ diff --git a/CHANGELOG.md b/CHANGELOG.md index a6bac7ee..402e0804 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,4 @@ -# What's new ? +- One file per exercise +- Indentation fixes +- Makefile update to clean latex compilation files -We now have artefacts from the CICD pipeline containing our built pdf. - -We are transforming our Markdown source files into LaTeX source files ! - -This changelog should appear for the first time in our release, with the built pdf diff --git a/Makefile b/Makefile index f0aeeee8..d828fdc8 100644 --- a/Makefile +++ b/Makefile @@ -13,6 +13,7 @@ all: clean dirs %.pdf: @echo "We are taking care of: $@" @$(MAKE) -C $(shell dirname $@) + @$(MAKE) clean -C $(shell dirname $@) cp $@ build/$(shell dirname `dirname $@`).pdf dirs: $(TARGETS_DIRS) diff --git a/README.md b/README.md index 4c099d9f..a9582ce5 100644 --- a/README.md +++ b/README.md @@ -24,9 +24,13 @@ - [Beta-testers](#beta-testers) - [Thanks to Ilyes and Kévin for the PR](#thanks-to-ilyes-and-kévin-for-the-pr) -This project is a Python programming and Machine Learning bootcamp created by [42 AI](http://www.42ai.fr). +>This project is a Python programming and Machine Learning bootcamp created by [42 AI](http://www.42ai.fr). +> +>No prior Python programming or Machine Learning experience is required! -No prior Python programming or Machine Learning experience is required! Your mission, should you choose to accept it, is to come and learn some of the essential knowledge for Machine Learning, Data Science and statistics, in a single week. You will start with the basics of the Python language and then get acquainted with some libraries that are invaluable to any programmer interested in the field of AI or data science. +Your mission, should you choose to accept it, is to learn some of the essential knowledge for Machine Learning, Data Science and statistics, in a single week. + +You will start with the basics of **Python** and then get acquainted with some libraries that are invaluable to any programmer interested in the field of AI or data science. 42 Artificial Intelligence is a student organization of the Paris campus of the school 42. Our purpose is to foster discussion, learning, and interest in the field of artificial intelligence, by organizing various activities such as lectures and workshops. @@ -68,6 +72,7 @@ The pdf files of each module can be downloaded from our realease page: * Tristan Duquesne (tduquesn@student.42.fr) * Pierre Peigné (ppeigne@student.42.fr) * Quentin Feuillade Montixi (qfeuilla@student.42.fr) +* Mathieu Perez (mathieu.perez@42ai.fr) ### Beta-testers diff --git a/assets/42ai_logo.png b/assets/42ai_logo.png index 1acb1bec..bc3764e1 100644 Binary files a/assets/42ai_logo.png and b/assets/42ai_logo.png differ diff --git a/build/module00.pdf b/build/module00.pdf index f540cd42..da4fee1e 100644 Binary files a/build/module00.pdf and b/build/module00.pdf differ diff --git a/build/module01.pdf b/build/module01.pdf index ba768263..c2f9826f 100644 Binary files a/build/module01.pdf and b/build/module01.pdf differ diff --git a/build/module02.pdf b/build/module02.pdf index b48806d6..a4721434 100644 Binary files a/build/module02.pdf and b/build/module02.pdf differ diff --git a/build/module03.pdf b/build/module03.pdf index d8be4428..aa129ce8 100644 Binary files a/build/module03.pdf and b/build/module03.pdf differ diff --git a/build/module04.pdf b/build/module04.pdf index af68bede..7fb0ef71 100644 Binary files a/build/module04.pdf and b/build/module04.pdf differ diff --git a/module00/subject/assets/42ai_logo.pdf b/module00/subject/assets/42ai_logo.pdf index c915fc5c..1f5d3abb 100644 Binary files a/module00/subject/assets/42ai_logo.pdf and b/module00/subject/assets/42ai_logo.pdf differ diff --git a/module00/subject/en.acknowledgements.tex b/module00/subject/en.acknowledgements.tex new file mode 100644 index 00000000..b6fdd85e --- /dev/null +++ b/module00/subject/en.acknowledgements.tex @@ -0,0 +1,38 @@ +\section*{Contact} +% --------------------------------- % +You can contact 42AI by email: \href{mailto:contact@42ai.fr}{contact@42ai.fr}\\ +\newline +Thank you for attending 42AI's Python Bootcamp module00 ! + +% ================================= % +\section*{Acknowledgements} +% --------------------------------- % +The Python bootcamp is the result of a collective work, for which we would like to thank: +\begin{itemize} + \item Maxime Choulika (cmaxime), + \item Pierre Peigné (ppeigne, pierre@42ai.fr), + \item Matthieu David (mdavid, matthieu@42ai.fr), + \item Quentin Feuillade--Montixi (qfeuilla, quentin@42ai.fr) + \item Mathieu Perez (maperez, mathieu.perez@42ai.fr) +\end{itemize} +who supervised the creation, the enhancement of the bootcamp and this present transcription. + +\begin{itemize} + \item Louis Develle (ldevelle, louis@42ai.fr) + \item Augustin Lopez (aulopez) + \item Luc Lenotre (llenotre) + \item Owen Roberts (oroberts) + \item Thomas Flahault (thflahau) + \item Amric Trudel (amric@42ai.fr) + \item Baptiste Lefeuvre (blefeuvr@student.42.fr) + \item Mathilde Boivin (mboivin@student.42.fr) + \item Tristan Duquesne (tduquesn@student.42.fr) +\end{itemize} +for your investment in the creation and development of these modules. + +\begin{itemize} + \item All prior participants who took a moment to provide their feedbacks, and help us improve these bootcamps ! +\end{itemize} + + \vfill +\doclicenseThis \ No newline at end of file diff --git a/module00/subject/en.py_proj.tex b/module00/subject/en.instructions.tex similarity index 68% rename from module00/subject/en.py_proj.tex rename to module00/subject/en.instructions.tex index 13773d61..8a1bd0c6 100644 --- a/module00/subject/en.py_proj.tex +++ b/module00/subject/en.instructions.tex @@ -10,8 +10,8 @@ \chapter{Common Instructions} \item The version of Python recommended to use is 3.7, you can check the version of Python with the following command: \texttt{python -V} - \item The norm: during this bootcamp you will follow the - \href{https://www.python.org/dev/peps/pep-0008/}{PEP 8 standards}. + \item The norm: during this bootcamp, it is recommended to follow the + \href{https://www.python.org/dev/peps/pep-0008/}{PEP 8 standards}, though it is not mandatory. You can install \href{https://pypi.org/project/pycodestyle}{pycodestyle} which is a tool to check your Python code. \item The function \texttt{eval} is never allowed. @@ -20,9 +20,12 @@ \chapter{Common Instructions} so make sure that your variable names and function names are appropriate and civil. \item Your manual is the internet. - \item You can also ask questions in the \texttt{\#bootcamps} channel in the \href{https://42-ai.slack.com}{42AI} - or \href{42born2code.slack.com}{42born2code}. - + \item If you are a student from 42, you can access our Discord server + on \href{https://discord.com/channels/887850395697807362/887850396314398720}{42 student's associations portal} and ask your + questions to your peers in the dedicated Bootcamp channel. + + \item You can learn more about 42 Artificial Intelligence by visiting \href{https://42-ai.github.io}{our website}. + \item If you find any issue or mistake in the subject please create an issue on \href{https://github.com/42-AI/bootcamp_python/issues}{42AI repository on Github}. \item We encourage you to create test programs for your @@ -32,10 +35,9 @@ \chapter{Common Instructions} those tests especially useful during your defence. Indeed, during defence, you are free to use your tests and/or the tests of the peer you are evaluating. - - \item Submit your work to your assigned git repository. Only the work in the - git repository will be graded. If Deepthought is assigned to grade your - work, it will be run after your peer-evaluations. - If an error happens in any section of your work during Deepthought's grading, - the evaluation will stop. + + \item We are constantly looking to improve these bootcamps, and your feedbacks are essential for us to do so !\\ + You can tell us more about your experience with this module by filling \href{https://forms.gle/89TZJDARdgZfghRPA}{this form}.\\ + Thank you in advance and good luck for this bootcamp ! + \end{itemize} \ No newline at end of file diff --git a/module00/subject/en.subject.pdf b/module00/subject/en.subject.pdf new file mode 100644 index 00000000..da4fee1e Binary files /dev/null and b/module00/subject/en.subject.pdf differ diff --git a/module00/subject/en.subject.pdf.version b/module00/subject/en.subject.pdf.version deleted file mode 100644 index 56a6051c..00000000 --- a/module00/subject/en.subject.pdf.version +++ /dev/null @@ -1 +0,0 @@ -1 \ No newline at end of file diff --git a/module00/subject/en.subject.tex b/module00/subject/en.subject.tex index bbe22325..c145b2c6 100644 --- a/module00/subject/en.subject.tex +++ b/module00/subject/en.subject.tex @@ -93,986 +93,74 @@ } \makeatother - \begin{document} % =============================================================================% % ===================================== % -\title{Python \& ML - Module 00} -\subtitle{Basic stuff - Eleven Commandments} -\author{ - Maxime Choulika (cmaxime), Pierre Peigné (ppeigne), Matthieu David (mdavid) -} - -\summary -{ - The goal of the module is to get started with the Python language. -} - +\title{Python Bootcamp - Module 00} +\subtitle{Basic stuff - The Eleven Commandments} +\author{} +\summary{The goal of this module is to get you started with Python} \maketitle -\input{en.py_proj.tex} +\input{en.instructions.tex} \newpage \tableofcontents \startexercices - % ===================================== % % =============================================================================% - - %******************************************************************************% % % % Exercises % % % %******************************************************************************% -% ============================================== % % ===========================(start ex 00) % -\chapter{Exercise 00} -\extitle{\$PATH} -\turnindir{ex00} -\exnumber{00} -\exfiles{answers.txt, requirements.txt} -\exforbidden{None} -\makeheaderfilesforbidden - -\emph{The first thing you need to do is install Python.} -\\\\ -Most modern Unix-based system have a \texttt{python} interpreter installed by default, -but its version might be lower/higher than the one used for these modules. -It is also possible that the default \texttt{python} command uses a version 2.x (for legacy reasons). -This is obviously very confusing for new developper. -\\ - -\begin{42console} -$> python -V -$> python3 -V -\end{42console} -\hfill \break -To deal with those version issues we will use \texttt{conda}. This program allow you to manage your Python packages and different working environments. -\\\\ -\emph{Note: the actual requirement is to use a Python 3.7.X version. You are free to use a different program/utilities to achieve this goal. At your own risk.} -\pagebreak - -% ===========================(Conda Manual) % -\section*{Conda manual installation} -\emph{Go the next section for an automated installation.} -\\\\ -We recommend the following path for your \texttt{conda} folder. -\begin{42console} -$> MYPATH="/goinfre/$USER/miniconda3" -\end{42console} - -% ---------------------------------- % -\subsection*{1. Download \& Install conda} - -\begin{42console} -# For MAC -$> curl -LO "https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh" -$> sh Miniconda3-latest-MacOSX-x86_64.sh -b -p $MYPATH - -# For Linux -$> curl -LO "https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh" -$> sh Miniconda3-latest-Linux-x86_64.sh -b -p $MYPATH -\end{42console} - - - -% ---------------------------------- % -\subsection*{2. Initial configuration of conda} -\begin{42console} -# For zsh -$> $MYPATH/bin/conda init zsh -$> $MYPATH/bin/conda config --set auto_activate_base false -$> source ~/.zshrc - -# For bash -$> $MYPATH/bin/conda init bash -$> $MYPATH/bin/conda config --set auto_activate_base false -$> source ~/.bash_profile -\end{42console} - - - -% ---------------------------------- % -\subsection*{3. Create an environment for 42AI !} -\begin{42console} -$> conda create --name 42AI-$USER python=3.7 jupyter pandas pycodestyle numpy -\end{42console} - - - -% ---------------------------------- % -\subsection*{4. Check your 42AI Python environment} -\begin{42console} -$> conda info --envs -$> conda activate 42AI-$USER -$> which python -$> python -V -$> python -c "print('Hello World!')" -\end{42console} - - - -% ---------------------------------- % -\subsection*{Help !} -\begin{itemize} - \item \textbf{I have lost my miniconda3 folder !} Repeat step 1 and 3. - \item \textbf{I have lost my home directory !} Repeat step 2. -\end{itemize} -\pagebreak - - - -% ===========================(Conda Auto) % -\section*{Conda automated installation} - -Copy the following script into a file, launch it and follow the instruction. It downloads miniconda, installs it in a \texttt{/goinfre} subfolder and creates a \texttt{python} environment in \texttt{conda}. - - -\begin{42console} -#!/bin/bash - -function which_dl { - # If operating system name contains Darwnin: MacOS. Else Linux - if uname -s | grep -iqF Darwin; then - echo "Miniconda3-latest-MacOSX-x86_64.sh" - else - echo "Miniconda3-latest-Linux-x86_64.sh" - fi -} - -function which_shell { - # if $SHELL contains zsh, zsh. Else Bash - if echo $SHELL | grep -iqF zsh; then - echo "zsh" - else - echo "bash" - fi -} - -function when_conda_exist { - # check and install 42AI environement - printf "Checking 42AI-$USER environment: " - if conda info --envs | grep -iqF 42AI-$USER; then - printf "\e[33mDONE\e[0m\n" - else - printf "\e[31mKO\e[0m\n" - printf "\e[33mCreating 42AI environnment:\e[0m\n" - conda update -n base -c defaults conda -y - conda create --name 42AI-$USER python=3.7 jupyter numpy pandas pycodestyle -y - fi -} - -function set_conda { - MINICONDA_PATH="/goinfre/$USER/miniconda3" - CONDA=$MINICONDA_PATH"/bin/conda" - PYTHON_PATH=$(which python) - REQUIREMENTS="jupyter numpy pandas pycodestyle" - SCRIPT=$(which_dl) - MY_SHELL=$(which_shell) - DL_LINK="https://repo.anaconda.com/miniconda/"$SCRIPT - DL_LOCATION="/tmp/" - - printf "Checking conda: " - TEST=$(conda -h 2>/dev/null) - if [ $? == 0 ] ; then - printf "\e[32mOK\e[0m\n" - when_conda_exist - return - fi - printf "\e[31mKO\e[0m\n" - if [ ! -f $DL_LOCATION$SCRIPT ]; then - printf "\e[33mDonwloading installer:\e[0m\n" - cd $DL_LOCATION - curl -LO $DL_LINK - cd - - fi - printf "\e[33mInstalling conda:\e[0m\n" - sh $DL_LOCATION$SCRIPT -b -p $MINICONDA_PATH - printf "\e[33mConda initial setup:\e[0m\n" - $CONDA init $MY_SHELL - $CONDA config --set auto_activate_base false - - printf "\e[33mCreating 42AI-$USER environnment:\e[0m\n" - $CONDA update -n base -c defaults conda -y - $CONDA create --name 42AI-$USER python=3.7 jupyter numpy pandas pycodestyle -y - printf "\e[33mLaunch the following command or restart your shell:\e[0m\n" - if [ $MY_SHELL == "zsh" ]; then - printf "\tsource ~/.zshrc\n" - else - printf "\tsource ~/.bash_profile\n" - fi -} - -set_conda -\end{42console} -\hfill \break -Don't forget to check your 42AI Python environment ! -\begin{42console} -conda info --envs -conda activate 42AI-$USER -which python -python -V -python -c "print('Hello World!')" -\end{42console} -\newpage - - - -% =================================(Question) % -\section*{(Finally) getting started} - -Now that your setup is ready to run, here's a few questions that need to be solved using \texttt{python}, \texttt{pip} or \texttt{conda}. Save your answers in a file \texttt{answers.txt} (one answer per line and per question), and check them with your peers.\\\\ -Find the commands to: -\begin{itemize} - \item Output a list of installed packages and their versions. - \item Show the package metadata of \texttt{numpy}. - \item Remove the package \texttt{numpy}. - \item (Re)install the package \texttt{numpy}. - \item Freeze your \texttt{python} packages and their versions in a \texttt{requirements.txt} file you have to turn-in. -\end{itemize} - - +\input{exercises/m00ex00.tex} % ===========================(fin ex 00) % \newpage % ===========================(start ex 01) % -\chapter{Exercise 01} -\extitle{Rev Alpha} -\turnindir{ex01} -\exnumber{01} -\exfiles{exec.py} -\exforbidden{None} -\makeheaderfilesforbidden - - -% ================================= % -% \section*{} -Make a program that takes a string as argument, reverses it, swaps its letters case and print the result. -\begin{itemize} - \item If more than one argument are provided, merge them into a single string with each argument separated by a space character. - \item If no argument are provided, do nothing or print an usage. -\end{itemize} - - -% --------------------------------- % -\section*{Examples} - -\begin{42console} -$> python3 exec.py 'Hello World!' | cat -e -!DLROw OLLEh$ -$> -$> python3 exec.py 'Hello' 'my Friend' | cat -e -DNEIRf YM OLLEh$ -$> -$> python3 exec.py -$> -\end{42console} - +\input{exercises/m00ex01.tex} % ===========================(fin ex 01) % \newpage % ===========================(start ex 02) % -\chapter{Exercise 02} -\extitle{The Odd, the Even and the Zero} -\turnindir{ex02} -\exnumber{02} -\exfiles{whois.py} -\exforbidden{None} -\makeheaderfilesforbidden - - -% ================================= % -% \section*{} -Make a program that takes a number as argument, checks whether it is odd, even or zero, and print the result. -\begin{itemize} - \item If more than one argument are provided or if the argument is not an integer, print an error message. - \item If no argument are provided, do nothing or print an usage. -\end{itemize} - - -% --------------------------------- % -\section*{Examples} -\begin{42console} -$> python3 whois.py 12 -I'm Even. -$> -$> python3 whois.py 3 -I'm Odd. -$> -$> python3 whois.py -$> -$> python3 whois.py 0 -I'm Zero. -$> -$> python3 whois.py Hello -AssertionError: argument is not an integer -$> -$> python3 whois.py 12 3 -AssertionError: more than one argument are provided -$> -\end{42console} - -\hint{ - No bonus point to be gained from a complex error management system. Keep it simple. -} - +\input{exercises/m00ex02.tex} % ===========================(fin ex 02) % \newpage % ===========================(start ex 03) % -\chapter{Exercise 03} -\extitle{Functional file} -\turnindir{ex03} -\exnumber{03} -\exfiles{count.py} -\exforbidden{None} -\makeheaderfilesforbidden - - -% ================================= % -\section*{Part 1. text\_analyzer} -Create a function called \texttt{text\_analyzer} that takes a single string argument -and displays the sums of its upper-case characters, lower-case characters, punctuation characters and spaces. -\begin{itemize} - \item If \texttt{None} or nothing is provided, the user is prompted to provide a string. - \item If the argument is not a string, print an error message. - \item This function must have a \texttt{docstring} explaning its behavior. -\end{itemize} - -Test your function with the \texttt{python} console - -% --------------------------------- % -\subsection*{Examples} -\begin{42console} -$> python3 ->>> from count import text_analyzer ->>> text_analyzer("Python 2.0, released 2000, introduced -features like List comprehensions and a garbage collection -system capable of collecting reference cycles.") -The text contains 143 character(s): -- 2 upper letter(s) -- 113 lower letter(s) -- 4 punctuation mark(s) -- 18 space(s) ->>> text_analyzer("Python is an interpreted, high-level, -general-purpose programming language. Created by Guido van -Rossum and first released in 1991, Python's design philosophy -emphasizes code readability with its notable use of significant -whitespace.") -The text contains 234 character(s): -- 5 upper letter(s) -- 187 lower letter(s) -- 8 punctuation mark(s) -- 30 space(s) ->>> text_analyzer() -What is the text to analyze? ->> Hello World! -The text contains 8 character(s): -- 2 upper letter(s) -- 8 lower letter(s) -- 1 punctuation mark(s) -- 1 space(s) ->>> text_analyzer(42) -AssertionError: argument is not a string ->>> print(text_analyzer.__doc__) - - This function counts the number of upper characters, lower characters, - punctuation and spaces in a given text. -\end{42console} - -% ================================= % -\section*{Part 2. \_\_name\_\_==\_\_main\_\_} - - -In the previous part, you wrote a function that can be used in the console or in another file when imported. -Without changing this behavior, update your file so it can also be launched as a standalone program. - -\begin{itemize} - \item If more than one argument is provided to the program, print an error message. - \item Otherwise, use the \texttt{text\_analyzer} function. -\end{itemize} - -% --------------------------------- % -\subsection*{Examples} -\begin{42console} -$> python3 count.py 'Hello World!' -The text contains 8 character(s): -- 2 upper letter(s) -- 8 lower letter(s) -- 1 punctuation mark(s) -- 1 space(s) -$> python3 ->>> from count import text_analyzer ->>> text_analyzer("Hello World!") -The text contains 8 character(s): -- 2 upper letter(s) -- 8 lower letter(s) -- 1 punctuation mark(s) -- 1 space(s) -\end{42console} - +\input{exercises/m00ex03.tex} % ===========================(fin ex 03) % \newpage % ===========================(start ex 04) % -\chapter{Exercise 04} -\extitle{Elementary} -\turnindir{ex04} -\exnumber{04} -\exfiles{operations.py} -\exforbidden{None} -\makeheaderfilesforbidden - - -% ================================= % -% \section*{} -Write a program that takes two integers A and B as arguments and prints the result of the following operations: -\begin{42console} -Sum: A+B -Difference: A-B -Product: A*B -Quotient: A/B -Remainder: A%B -\end{42console} - -\begin{itemize} - \item If more or less than two argument are provided or if either of the argument is not an integer, print an error message. - \item If no argument are provided, do nothing or print an usage. - \item If an operation is impossible, print an error message instead of a numerical result. -\end{itemize} - -% ================================= % -\section*{Examples} -\begin{42console} -$> python3 operations.py 10 3 -Sum: 13 -Difference: 7 -Product: 30 -Quotient: 3.3333... -Remainder: 1 -$> -$> python3 operations.py 42 10 -Sum: 52 -Difference: 32 -Product: 420 -Quotient: 4.2 -Remainder: 2 -$> -$> python3 operations.py 1 0 -Sum: 1 -Difference: 1 -Product: 0 -Quotient: ERROR (division by zero) -Remainder: ERROR (modulo by zero) -$> -$> python3 operations.py -Usage: python operations.py -Example: - python operations.py 10 3 -$> -$> python3 operations.py 12 10 5 -AssertionError: too many arguments -$> -$> python3 operations.py "one" "two" -AssertionError: only integers -$> -\end{42console} - -\hint{ - No bonus point to be gained from handling decimal point or scientific notation. Keep it simple. -} - +\input{exercises/m00ex04.tex} % ===========================(fin ex 04) % \newpage % ===========================(start ex 05) % - -\chapter{Exercise 05} -\extitle{The right format} -\turnindir{ex05} -\exnumber{05} -\exfiles{kata00.py, kata01.py, kata02.py, kata03.py, kata04.py} -\exforbidden{None} -\makeheaderfilesforbidden - -Let's get familiar with the useful concept of \textbf{string formatting} through a kata series.\\ - -Each exercice will provide you with a \texttt{kata} variable. This variable can be modified to a certain extent: your program must react accordingly. - -% ================================= % -\section*{kata00} -The \texttt{kata} variable is always a tuple and can only be filled with integer. -\begin{42console} -# Put this at the top of your kata00.py file -kata = (19,42,21) -\end{42console} - -Write a program that display this variable content according to the format shown below: - -\begin{42console} -$> python3 kata00.py -The 3 numbers are: 19, 42, 21 -$> -\end{42console} - -% ================================= % -\section*{kata01} - -The \texttt{kata} variable is always a dictionary and can only be filled with strings. - -\begin{42console} -# Put this at the top of your kata01.py file -kata = { - 'Python': 'Guido van Rossum', - 'Ruby': 'Yukihiro Matsumoto', - 'PHP': 'Rasmus Lerdorf', - } -\end{42console} - -Write a program that display this variable content according to the format shown below: - -\begin{42console} -$> python3 kata01.py -Python was created by Guido van Rossum -Ruby was created by Yukihiro Matsumoto -PHP was created by Rasmus Lerdorf -$> -\end{42console} - -% ================================= % -\section*{kata02} - -The \texttt{kata} variable is always a tuple that contains 5 non-negative integers. The first integer contains up to 4 digits, the rest up to 2 digits. - -\begin{42console} -# Put this at the top of your kata02.py file -kata = (2019, 9, 25, 3, 30) -\end{42console} - -Write a program that display this variable content according to the format shown below: - -\begin{42console} -$> python3 kata02.py | cat -e -09/25/2019 03:30$ -$> python3 kata02.py | wc -c -17 -$> -\end{42console} - -% ================================= % -\section*{kata03} - -The \texttt{kata} variable is always a string whose length is not higher than 42. - -\begin{42console} -# Put this at the top of your kata03.py file -kata = "The right format" -\end{42console} - -Write a program that display this variable content according to the format shown below: - -\begin{42console} -$> python3 kata03.py | cat -e ---------------------------The right format% -$> python3 kata03.py | wc -c -42 -$> -\end{42console} - -% ================================= % -\section*{kata04} - -The \texttt{kata} variable is always a tuple that contains, in the following order: -\begin{itemize} - \item 2 non-negative integer containing up to 2 digits - \item 1 decimal - \item 1 integer - \item 1 decimal -\end{itemize} - -\begin{42console} -# Put this at the top of your kata04.py file -kata = (0, 4, 132.42222, 10000, 12345.67) -\end{42console} - -Write a program that display this variable content according to the format shown below: - -\begin{42console} -$> python3 kata04.py -module_00, ex_04 : 132.42, 1.00e+04, 1.23e+04 -$> python3 kata04.py | cut -c 10,18 -,: -\end{42console} - +\input{exercises/m00ex05.tex} % ===========================(fin ex 05) % \newpage % ===========================(start ex 06) % -\chapter{Exercise 06} -\extitle{A recipe} -\turnindir{ex06} -\exnumber{06} -\exfiles{recipe.py} -\exforbidden{None} -\makeheaderfilesforbidden - -% ================================= % -\section*{Part 1: Nested Dictionaries} - -Create a dictionary called \texttt{cookbook}. You will use this \texttt{cookbook} to store recipe. -\\\\ -A recipe is a \textbf{dictionary} that stores (at least) 3 couples key-value: -\begin{itemize} - \item ''ingredients": a \textbf{list of string} representing the list of ingredients - \item "meal": a \textbf{string} representing the type of meal - \item "prep\_time": a \textbf{non-negative integer} representing a time in minutes -\end{itemize} - -In the \texttt{cookbook}, the \textbf{key} to a recipe is the recipe name. -\\ -Initialize your \texttt{cookbook} with 3 recipes: -\begin{itemize} - \item The Sandwich's ingredients are \textit{ham}, \textit{bread}, \textit{cheese} and \textit{tomatoes}. -It is a \textit{lunch} and it takes $10$ minutes of preparation. - \item The Cake's ingredients are \textit{flour}, \textit{sugar} and \textit{eggs}. -It is a \textit{dessert} and it takes $60$ minutes of preparation. - \item The Salad's ingredients are \textit{avocado}, \textit{arugula}, \textit{tomatoes} and \textit{spinach}. -It is a \textit{lunch} and it takes $15$ minutes of preparation. -\end{itemize} - -% ================================= % -\section*{Part 2: A series of Helpful Functions} - -Create a series of useful functions to handle your \texttt{cookbook}: - -\begin{enumerate} - \item A function that print all recipe names. - \item A function that takes a recipe name and print its details. - \item A function that takes a recipe name and delete it. - \item A function that add a recipe from user input. You will need a name, a list of ingredient, a meal type and a preparation time. -\end{enumerate} -\subsection*{input example} -\begin{42console} ->>> Enter a name: -chips ->>> Enter ingredients: -potatoes -oil -salt - ->>> Enter a meal type: -lunch ->>> Enter a preparation time: -15 -\end{42console} - -% ================================= % -\section*{Part 3: A command line executable !} - -Create a program that use your \texttt{cookbook} and your functions.\\ - -The program will prompt the user to make a choice between printing the cookbook content, printing one recipe, adding a recipe, deleting a recipe or quitting the cookbook.\\ - -Your program will continue to ask for prompt until the user decide to quit it. The program cannot crash if a wrong value is entered: you must handle the error and ask for another prompt. - -\begin{42console} -$> python3 recipe.py -Welcome to the Python Cookbook ! -List of available option: - 1: Add a recipe - 2: Delete a recipe - 3: Print a recipe - 4: Print the cookbook - 5: Quit - -Please select an option: ->> 3 - -Please enter a recipe name to get its details: ->> cake - -Recipe for cake: - Ingredients list: ['flour', 'sugar', 'eggs'] - To be eaten for dessert. - Takes 60 minutes of cooking. - -Please select an option: ->> Hello - -Sorry, this option does not exist. -List of available option: - 1: Add a recipe - 2: Delete a recipe - 3: Print a recipe - 4: Print the cookbook - 5: Quit - -Please select an option: ->> 5 - -Cookbook closed. Goodbye ! -$> -\end{42console} - - +\input{exercises/m00ex06.tex} % ===========================(fin ex 06) % \newpage % ===========================(start ex 07) % -\chapter{Exercise 07} -\extitle{Shorter, faster, pythonest} -\turnindir{ex07} -\exnumber{07} -\exfiles{filterwords.py} -\exforbidden{filter} -\makeheaderfilesforbidden - -Make a program that takes a string S and an integer N as argument and print the list of words in S that contains more than N non-punctuation characters. - -\begin{itemize} - \item Words are separated from each other by space characters - \item Punctuation symbols must be removed from the printed list: they are neither part of a word nor a separator - \item The program must contains at least one \textbf{list comprehension} expression. -\end{itemize} - -If the number of argument is different from 2, or if the type of any argument is wrong, the program prints an error message. - -% ================================= % -\section*{Examples} -% --------------------------------- % - -\begin{42console} -$> python3 filterwords.py 'Hello, my friend' 3 -['Hello', 'friend'] -$> python3 filterwords.py 'Hello, my friend' 10 -[] -$> python3 filterwords.py 'A robot must protect its own existence as long as such protection does not conflict with the First or Second Law' 6 -['protect', 'existence', 'protection', 'conflict'] -$> python3 filterwords.py Hello World -ERROR -$> python3 filterwords.py 3 'Hello, my friend' -ERROR -$> python3 filterwords.py -ERROR -\end{42console} - +\input{exercises/m00ex07.tex} % ===========================(fin ex 07) % \newpage % ===========================(start ex 08) % -\chapter{Exercise 08} -\extitle{S.O.S} -\turnindir{ex08} -\exnumber{08} -\exfiles{sos.py} -\exforbidden{None} -\makeheaderfilesforbidden - -Make a program that takes a string as argument and encode it into Morse code. - -\begin{itemize} - \item The program supports space and alphanumeric characters - \item An alphanumeric character is represented by dots \texttt{.} and dashes \texttt{-}: - \item A space character is represented by a slash \texttt{/} - \item Complete morse characters are separated by a single space\\ -\end{itemize} - -If more than one argument are provided, merge them into a single string with each argument separated by a space character.\\ - -If no argument is provided, do nothing or print an usage. - -% ================================= % -\section*{Examples} -\begin{42console} - $> python3 sos.py "SOS" - ... --- ... - $> python3 sos.py - $> python3 sos.py "HELLO / WORLD" - ERROR - $> python3 sos.py "96 BOULEVARD" "Bessiere" - ----. -.... / -... --- ..- .-.. . ...- .- .-. -.. / -... . ... ... .. . .-. . -\end{42console} - - -\hint{ - \url{https://morsecode.world/international/morse2.html} -} +\input{exercises/m00ex08.tex} % ===========================(fin ex 08) % -% ============================================== % - \newpage - -% ============================================== % % ===========================(start ex 09) % -\chapter{Exercise 09} -\extitle{Secret number} -\turnindir{ex09} -\exnumber{09} -\exfiles{guess.py} -\exforbidden{None} -\makeheaderfilesforbidden - -You have to make a program that will be an interactive guessing game. -It will ask the user to guess a number between $1$ and $99$. -The program will tell the user if their input is too high or too low. -The game ends when the user finds out the secret number or types \texttt{exit}. -You will import the \texttt{random} module with the \texttt{randint} function to get a random number. -You have to count the number of trials and print that number when the user wins. - -% ================================= % -\section*{Examples} -% --------------------------------- % - -\begin{42console} - $> python guess.py - This is an interactive guessing game! - You have to enter a number between 1 and 99 to find out the secret number. - Type 'exit' to end the game. - Good luck! - - What's your guess between 1 and 99? - >> 54 - Too high! - What's your guess between 1 and 99? - >> 34 - Too low! - What's your guess between 1 and 99? - >> 45 - Too high! - What's your guess between 1 and 99? - >> A - That's not a number. - What's your guess between 1 and 99? - >> 43 - Congratulations, you've got it! - You won in 5 attempts! -\end{42console} - -If the user discovers the secret number on the first try, tell them. -If the secret number is 42, make a reference to Douglas Adams. - -\begin{42console} - $> python guess.py - This is an interactive guessing game! - You have to enter a number between 1 and 99 to find out the secret number. - Type 'exit' to end the game. - Good luck! - - What's your guess between 1 and 99? - >> 42 - The answer to the ultimate question of life, the universe and everything is 42. - Congratulations! You got it on your first try! -\end{42console} - - -Other example: - -\begin{42console} - $> python guess.py - This is an interactive guessing game! - You have to enter a number between 1 and 99 to find out the secret number. - Type 'exit' to end the game. - Good luck! - - What's your guess between 1 and 99? - >> exit - Goodbye! -\end{42console} - +\include{exercises/m00ex09.tex} % ===========================(fin ex 09) % -% ============================================== % - \newpage - -% ============================================== % % ===========================(start ex 10) % -\chapter{Exercise 10} -\extitle{Loading bar!} -\turnindir{ex10} -\exnumber{10} -\exfiles{loading.py} -\exforbidden{None} -\makeheaderfilesforbidden - - -You are about to discover the \texttt{yield} operator! - -So let's create a function called \texttt{ft\_progress(lst)}. - -The function will display the progress of a \texttt{for} loop. - - -% ================================= % -\section*{Examples} -% --------------------------------- % -\begin{42console}% SERAIT MIEUX AVEC UN ENVIRONNEMENT PYTHON - listy = range(1000) - ret = 0 - for elem in ft_progress(listy): - ret += (elem + 3) % 5 - sleep(0.01) - print() - print(ret) -\end{42console} - -\begin{42console} - $> python loading.py - ETA: 8.67s [ 23%][=====> ] 233/1000 | elapsed time 2.33s - ... - 2000 -\end{42console} - -\begin{42console}% SERAIT MIEUX AVEC UN ENVIRONNEMENT PYTHON - listy = range(3333) - ret = 0 - for elem in ft_progress(listy): - ret += elem - sleep(0.005) - print() - print(ret) -\end{42console} - -\begin{42console} - $> python loading.py - ETA: 14.67s [ 9%][=> ] 327/3333 | elapsed time 1.33s - ... - 5552778 -\end{42console} - - +\include{exercises/m00ex10.tex} % ===========================(fin ex 10) % -% ============================================== % \newpage % ================================= % -\section*{Contact} -% --------------------------------- % -You can contact 42AI association by email: contact@42ai.fr\\ -You can join the association on \href{https://join.slack.com/t/42-ai/shared_invite/zt-ebccw5r7-YPkDM6xOiYRPjqJXkrKgcA}{42AI slack} -and/or apply to \href{https://forms.gle/VAFuREWaLmaqZw2D8}{one of the association teams}. - +\input{en.acknowledgements.tex} % ================================= % -\section*{Acknowledgements} -% --------------------------------- % -The modules Python \& ML is the result of a collective work, we would like to thanks: -\begin{itemize} - \item Maxime Choulika (cmaxime), - \item Pierre Peigné (ppeigne), - \item Matthieu David (mdavid). -\end{itemize} -who supervised the creation, the enhancement and this present transcription. - -\begin{itemize} - \item Amric Trudel (amric@42ai.fr) - \item Baptiste Lefeuvre (blefeuvr@student.42.fr) - \item Mathilde Boivin (mboivin@student.42.fr) - \item Tristan Duquesne (tduquesn@student.42.fr) - \item Quentin Feuillade Montixi (qfeuilla@student.42.fr) -\end{itemize} -for your investment for the creation and development of these modules. - -\begin{itemize} - \item Barthélémy Leveque (bleveque@student.42.fr) - \item Remy Oster (roster@student.42.fr) - \item Quentin Bragard (qbragard@student.42.fr) - \item Marie Dufourq (madufour@student.42.fr) - \item Adrien Vardon (advardon@student.42.fr) -\end{itemize} -who betatest the first version of the modules of Machine Learning. -\vfill -\doclicenseThis \end{document} diff --git a/module00/subject/exercises/m00ex00.tex b/module00/subject/exercises/m00ex00.tex new file mode 100644 index 00000000..1df99f1f --- /dev/null +++ b/module00/subject/exercises/m00ex00.tex @@ -0,0 +1,202 @@ +\chapter{Exercise 00} +\extitle{\$PATH} +\turnindir{ex00} +\exnumber{00} +\exfiles{answers.txt, requirements.txt} +\exforbidden{None} +\makeheaderfilesforbidden\\ +\emph{The first thing you need to do is to install Python.} +\\\\ +Most modern Unix-based systems have a \texttt{python} interpreter installed by default, +but its version might be lower/higher than the one used for these modules. +It is also possible that the default \texttt{python} command uses a version 2.x (for legacy reasons). +This is obviously very confusing for a new developper. +\\ + +\begin{42console} +$> python -V +$> python3 -V +\end{42console} +\hfill \break +To deal with those versions issues we will use \texttt{conda}. This program allows you to manage your Python packages and several working environments. +\\\\ +\emph{Note: the actual requirement is to use a Python 3.7.X version. You are free to use a different program/utilities to achieve this goal. At your own risk.} +\pagebreak + +% ===========================(Conda Manual) % +\section*{Conda manual installation} +\emph{Go to the next section for an automated installation.} +\\\\ +We recommend the following path for your \texttt{conda} folder. +\begin{42console} +$> MYPATH="/goinfre/$USER/miniconda3" +\end{42console} + +% ---------------------------------- % +\subsection*{1. Download \& Install conda} + +\begin{42console} +# For MAC +$> curl -LO "https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh" +$> sh Miniconda3-latest-MacOSX-x86_64.sh -b -p $MYPATH + +# For Linux +$> curl -LO "https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh" +$> sh Miniconda3-latest-Linux-x86_64.sh -b -p $MYPATH +\end{42console} + + + +% ---------------------------------- % +\subsection*{2. Initial configuration of conda} +\begin{42console} +# For zsh +$> $MYPATH/bin/conda init zsh +$> $MYPATH/bin/conda config --set auto_activate_base false +$> source ~/.zshrc + +# For bash +$> $MYPATH/bin/conda init bash +$> $MYPATH/bin/conda config --set auto_activate_base false +$> source ~/.bash_profile +\end{42console} + + + +% ---------------------------------- % +\subsection*{3. Create a dedicated environment for 42AI !} +\begin{42console} +$> conda create --name 42AI-$USER python=3.7 jupyter pandas pycodestyle numpy +\end{42console} + + + +% ---------------------------------- % +\subsection*{4. Check your 42AI Python environment} +\begin{42console} +$> conda info --envs +$> conda activate 42AI-$USER +$> which python +$> python -V +$> python -c "print('Hello World!')" +\end{42console} + + + +% ---------------------------------- % +\subsection*{Help !} +\begin{itemize} + \item \textbf{I have lost my miniconda3 folder !} Repeat step 1 and 3. + \item \textbf{I have lost my home directory !} Repeat step 2. +\end{itemize} +\pagebreak + + + +% ===========================(Conda Auto) % +\section*{Conda automated installation} + +Copy the following script into a file, launch it and follow the instructions. It downloads and installs miniconda in a \texttt{/goinfre} subfolder and creates a \texttt{python} environment in \texttt{conda}. + + +\begin{42console} +#!/bin/bash + +function which_dl { + # If operating system name contains Darwnin: MacOS. Else Linux + if uname -s | grep -iqF Darwin; then + echo "Miniconda3-latest-MacOSX-x86_64.sh" + else + echo "Miniconda3-latest-Linux-x86_64.sh" + fi +} + +function which_shell { + # if $SHELL contains zsh, zsh. Else Bash + if echo $SHELL | grep -iqF zsh; then + echo "zsh" + else + echo "bash" + fi +} + +function when_conda_exist { + # check and install 42AI environement + printf "Checking 42AI-$USER environment: " + if conda info --envs | grep -iqF 42AI-$USER; then + printf "\e[33mDONE\e[0m\n" + else + printf "\e[31mKO\e[0m\n" + printf "\e[33mCreating 42AI environnment:\e[0m\n" + conda update -n base -c defaults conda -y + conda create --name 42AI-$USER python=3.7 jupyter numpy pandas pycodestyle -y + fi +} + +function set_conda { + MINICONDA_PATH="/goinfre/$USER/miniconda3" + CONDA=$MINICONDA_PATH"/bin/conda" + PYTHON_PATH=$(which python) + REQUIREMENTS="jupyter numpy pandas pycodestyle" + SCRIPT=$(which_dl) + MY_SHELL=$(which_shell) + DL_LINK="https://repo.anaconda.com/miniconda/"$SCRIPT + DL_LOCATION="/tmp/" + + printf "Checking conda: " + TEST=$(conda -h 2>/dev/null) + if [ $? == 0 ] ; then + printf "\e[32mOK\e[0m\n" + when_conda_exist + return + fi + printf "\e[31mKO\e[0m\n" + if [ ! -f $DL_LOCATION$SCRIPT ]; then + printf "\e[33mDonwloading installer:\e[0m\n" + cd $DL_LOCATION + curl -LO $DL_LINK + cd - + fi + printf "\e[33mInstalling conda:\e[0m\n" + sh $DL_LOCATION$SCRIPT -b -p $MINICONDA_PATH + printf "\e[33mConda initial setup:\e[0m\n" + $CONDA init $MY_SHELL + $CONDA config --set auto_activate_base false + + printf "\e[33mCreating 42AI-$USER environnment:\e[0m\n" + $CONDA update -n base -c defaults conda -y + $CONDA create --name 42AI-$USER python=3.7 jupyter numpy pandas pycodestyle -y + printf "\e[33mLaunch the following command or restart your shell:\e[0m\n" + if [ $MY_SHELL == "zsh" ]; then + printf "\tsource ~/.zshrc\n" + else + printf "\tsource ~/.bash_profile\n" + fi +} + +set_conda +\end{42console} +\hfill \break +Don't forget to check your 42AI Python environment ! +\begin{42console} +conda info --envs +conda activate 42AI-$USER +which python +python -V +python -c "print('Hello World!')" +\end{42console} + +% =================================(Question) % +\section*{(Finally) getting started} + +Now that your setup is ready to run, here are a few questions that need to be solved using \texttt{python}, \texttt{pip} or \texttt{conda}. Save your answers in a file \texttt{answers.txt} (one answer per line and per question), and check them with your peers.\\\\ +Find the commands to: +\begin{itemize} + \item Output a list of installed packages and their versions. + \item Show the package metadata of \texttt{numpy}. + \item Remove the package \texttt{numpy}. + \item (Re)install the package \texttt{numpy}. + \item Freeze your \texttt{python} packages and their versions in a \texttt{requirements.txt} file you have to turn-in. +\end{itemize} + + diff --git a/module00/subject/exercises/m00ex01.tex b/module00/subject/exercises/m00ex01.tex new file mode 100644 index 00000000..a0836e06 --- /dev/null +++ b/module00/subject/exercises/m00ex01.tex @@ -0,0 +1,27 @@ +\chapter{Exercise 01} +\extitle{Rev Alpha} +\turnindir{ex01} +\exnumber{01} +\exfiles{exec.py} +\exforbidden{None} +\makeheaderfilesforbidden +\newline +Make a program that takes a string as argument, reverses it, swaps its letters case and prints the result. + +\begin{itemize} + \item If more than one argument is provided, merge them into a single string with each argument separated by a single space character. + \item If no argument is provided, do nothing or print an usage. +\end{itemize} +% --------------------------------- % +\section*{Examples} + +\begin{42console} +$> python3 exec.py 'Hello World!' | cat -e +!DLROw OLLEh$ +$> +$> python3 exec.py 'Hello' 'my Friend' | cat -e +DNEIRf YM OLLEh$ +$> +$> python3 exec.py +$> +\end{42console} diff --git a/module00/subject/exercises/m00ex02.tex b/module00/subject/exercises/m00ex02.tex new file mode 100644 index 00000000..94fe7481 --- /dev/null +++ b/module00/subject/exercises/m00ex02.tex @@ -0,0 +1,38 @@ +\chapter{Exercise 02} +\extitle{The Odd, the Even and the Zero} +\turnindir{ex02} +\exnumber{02} +\exfiles{whois.py} +\exforbidden{None} +\makeheaderfilesforbidden +Make a program that takes a number as argument, checks whether it is odd, even or zero, and prints the result. +\begin{itemize} + \item If more than one argument is provided or if the argument is not an integer, print an error message. + \item If no argument is provided, do nothing or print an usage. +\end{itemize} + +% --------------------------------- % +\section*{Examples} +\begin{42console} +$> python3 whois.py 12 +I'm Even. +$> +$> python3 whois.py 3 +I'm Odd. +$> +$> python3 whois.py +$> +$> python3 whois.py 0 +I'm Zero. +$> +$> python3 whois.py Hello +AssertionError: argument is not an integer +$> +$> python3 whois.py 12 3 +AssertionError: more than one argument is provided +$> +\end{42console} + +\hint{ + No bonus point to be gained from a complex error management system. Keep it simple. +} diff --git a/module00/subject/exercises/m00ex03.tex b/module00/subject/exercises/m00ex03.tex new file mode 100644 index 00000000..af0766d1 --- /dev/null +++ b/module00/subject/exercises/m00ex03.tex @@ -0,0 +1,89 @@ +\chapter{Exercise 03} +\extitle{Functional file} +\turnindir{ex03} +\exnumber{03} +\exfiles{count.py} +\exforbidden{None} +\makeheaderfilesforbidden +\section*{Part 1. text\_analyzer} +Create a function called \texttt{text\_analyzer} that takes a single string argument +and displays the total number of printable characters, and respectively : the number of upper-case characters, lower-case characters, punctuation characters and spaces. +\begin{itemize} + \item If \texttt{None} or nothing is provided, the user is prompted to provide a string. + \item If the argument is not a string, print an error message. + \item This function must have a \texttt{docstring} explaning its behavior. +\end{itemize} +Test your function within the \texttt{python} console + +% --------------------------------- % +\subsection*{Examples} +\begin{42console} +$> python3 +>>> from count import text_analyzer +>>> text_analyzer("Python 2.0, released 2000, introduced +features like List comprehensions and a garbage collection +system capable of collecting reference cycles.") +The text contains 143 printable character(s): +- 2 upper letter(s) +- 113 lower letter(s) +- 4 punctuation mark(s) +- 18 space(s) +>>> text_analyzer("Python is an interpreted, high-level, +general-purpose programming language. Created by Guido van +Rossum and first released in 1991, Python's design philosophy +emphasizes code readability with its notable use of significant +whitespace.") +The text contains 234 printable character(s): +- 5 upper letter(s) +- 187 lower letter(s) +- 8 punctuation mark(s) +- 30 space(s) +>>> text_analyzer() +What is the text to analyze? +>> Hello World! +The text contains 12 printable character(s): +- 2 upper letter(s) +- 8 lower letter(s) +- 1 punctuation mark(s) +- 1 space(s) +>>> text_analyzer(42) +AssertionError: argument is not a string +>>> print(text_analyzer.__doc__) + + This function counts the number of upper characters, lower characters, + punctuation and spaces in a given text. +\end{42console} + +\hint{ + Python has a lot of very convenient built-in functions and methods. Do some research, you do not have to reivent the wheel ! +} + +% ================================= % +\section*{Part 2. \_\_name\_\_==\_\_main\_\_} + +In the previous part, you wrote a function that can be used in the console or in another file when imported. +Without changing this behavior, update your file so it can also be launched as a standalone program. + +\begin{itemize} + \item If more than one argument is provided to the program, print an error message. + \item Otherwise, use the \texttt{text\_analyzer} function. +\end{itemize} + +% --------------------------------- % +\subsection*{Examples} +\begin{42console} +$> python3 count.py 'Hello World!' +The text contains 12 character(s): +- 2 upper letter(s) +- 8 lower letter(s) +- 1 punctuation mark(s) +- 1 space(s) +$> python3 +>>> from count import text_analyzer +>>> text_analyzer("Hello World!") +The text contains 12 character(s): +- 2 upper letter(s) +- 8 lower letter(s) +- 1 punctuation mark(s) +- 1 space(s) +\end{42console} \ No newline at end of file diff --git a/module00/subject/exercises/m00ex04.tex b/module00/subject/exercises/m00ex04.tex new file mode 100644 index 00000000..aeac1fd1 --- /dev/null +++ b/module00/subject/exercises/m00ex04.tex @@ -0,0 +1,63 @@ +\chapter{Exercise 04} +\extitle{Elementary} +\turnindir{ex04} +\exnumber{04} +\exfiles{operations.py} +\exforbidden{None} +\makeheaderfilesforbidden\\ +Write a program that takes two integers A and B as arguments and prints the result of the following operations: +\newline +\begin{42console} +Sum: A+B +Difference: A-B +Product: A*B +Quotient: A/B +Remainder: A%B +\end{42console} + +\begin{itemize} + \item If more or less than two arguments are provided or if one of the arguments is not an integer, print an error message. + \item If no argument is provided, do nothing or print an usage. + \item If an operation is impossible, print an error message instead of a numerical result. +\end{itemize} + +% ================================= % +\section*{Examples} +\begin{42console} +$> python3 operations.py 10 3 +Sum: 13 +Difference: 7 +Product: 30 +Quotient: 3.3333... +Remainder: 1 +$> +$> python3 operations.py 42 10 +Sum: 52 +Difference: 32 +Product: 420 +Quotient: 4.2 +Remainder: 2 +$> +$> python3 operations.py 1 0 +Sum: 1 +Difference: 1 +Product: 0 +Quotient: ERROR (division by zero) +Remainder: ERROR (modulo by zero) +$> +$> python3 operations.py +Usage: python operations.py +Example: + python operations.py 10 3 +$> +$> python3 operations.py 12 10 5 +AssertionError: too many arguments +$> +$> python3 operations.py "one" "two" +AssertionError: only integers +$> +\end{42console} + +\hint{ + No bonus point to be gained from handling decimal point or scientific notation. Keep it simple. +} \ No newline at end of file diff --git a/module00/subject/exercises/m00ex05.tex b/module00/subject/exercises/m00ex05.tex new file mode 100644 index 00000000..54a0d7e6 --- /dev/null +++ b/module00/subject/exercises/m00ex05.tex @@ -0,0 +1,109 @@ +\chapter{Exercise 05} +\extitle{The right format} +\turnindir{ex05} +\exnumber{05} +\exfiles{kata00.py, kata01.py, kata02.py, kata03.py, kata04.py} +\exforbidden{None} +\makeheaderfilesforbidden +Let's get familiar with the useful concept of \textbf{string formatting} through a kata series.\\ +\newline +Each exercice will provide you with a \texttt{kata} variable. This variable can be modified to a certain extent: your program must react accordingly. +% ================================= % +\section*{kata00} +The \texttt{kata} variable is always a tuple and can only be filled with integers. +\begin{42console} +# Put this at the top of your kata00.py file +kata = (19,42,21) +\end{42console} +Write a program that displays this variable content according to the format shown below: + +\begin{42console} +$> python3 kata00.py +The 3 numbers are: 19, 42, 21 +$> +\end{42console} + +% ================================= % +\section*{kata01} + +The \texttt{kata} variable is always a dictionary and can only be filled with strings. + +\begin{42console} +# Put this at the top of your kata01.py file +kata = { + 'Python': 'Guido van Rossum', + 'Ruby': 'Yukihiro Matsumoto', + 'PHP': 'Rasmus Lerdorf', + } +\end{42console} +Write a program that displays this variable content according to the format shown below: + +\begin{42console} +$> python3 kata01.py +Python was created by Guido van Rossum +Ruby was created by Yukihiro Matsumoto +PHP was created by Rasmus Lerdorf +$> +\end{42console} + +% ================================= % +\section*{kata02} + +The \texttt{kata} variable is always a tuple that contains 5 non-negative integers. The first integer contains up to 4 digits, the rest up to 2 digits. + +\begin{42console} +# Put this at the top of your kata02.py file +kata = (2019, 9, 25, 3, 30) +\end{42console} +Write a program that displays this variable content according to the format shown below: + +\begin{42console} +$> python3 kata02.py | cat -e +09/25/2019 03:30$ +$> python3 kata02.py | wc -c +17 +$> +\end{42console} + +% ================================= % +\section*{kata03} + +The \texttt{kata} variable is always a string whose length is not higher than 42. + +\begin{42console} +# Put this at the top of your kata03.py file +kata = "The right format" +\end{42console} +Write a program that displays this variable content according to the format shown below: + +\begin{42console} +$> python3 kata03.py | cat -e +--------------------------The right format% +$> python3 kata03.py | wc -c +42 +$> +\end{42console} + +% ================================= % +\section*{kata04} + +The \texttt{kata} variable is always a tuple that contains, in the following order: +\begin{itemize} + \item 2 non-negative integers containing up to 2 digits + \item 1 decimal + \item 1 integer + \item 1 decimal +\end{itemize} + +\begin{42console} +# Put this at the top of your kata04.py file +kata = (0, 4, 132.42222, 10000, 12345.67) +\end{42console} +Write a program that displays this variable content according to the format shown below: + +\begin{42console} +$> python3 kata04.py +module_00, ex_04 : 132.42, 1.00e+04, 1.23e+04 +$> python3 kata04.py | cut -c 10,18 +,: +\end{42console} \ No newline at end of file diff --git a/module00/subject/exercises/m00ex06.tex b/module00/subject/exercises/m00ex06.tex new file mode 100644 index 00000000..6fe4d0ed --- /dev/null +++ b/module00/subject/exercises/m00ex06.tex @@ -0,0 +1,108 @@ +\chapter{Exercise 06} +\extitle{A recipe} +\turnindir{ex06} +\exnumber{06} +\exfiles{recipe.py} +\exforbidden{None} +\makeheaderfilesforbidden + +% ================================= % +\section*{Part 1: Nested Dictionaries} + +Create a dictionary called \texttt{cookbook}. You will use this \texttt{cookbook} to store recipes. +\\\\ +A recipe is a \textbf{dictionary} that stores (at least) 3 key-value pairs: +\begin{itemize} + \item ''ingredients": a \textbf{list of strings} containing the list of ingredients + \item "meal": a \textbf{string} representing the type of meal + \item "prep\_time": a \textbf{non-negative integer} representing a preparation time in minutes +\end{itemize} +In the \texttt{cookbook}, the \textbf{key} to a recipe is the recipe's name. +\\ +Initialize your \texttt{cookbook} with 3 recipes: +\begin{itemize} + \item The Sandwich's ingredients are \textit{ham}, \textit{bread}, \textit{cheese} and \textit{tomatoes}. +It is a \textit{lunch} and it takes $10$ minutes of preparation. + \item The Cake's ingredients are \textit{flour}, \textit{sugar} and \textit{eggs}. +It is a \textit{dessert} and it takes $60$ minutes of preparation. + \item The Salad's ingredients are \textit{avocado}, \textit{arugula}, \textit{tomatoes} and \textit{spinach}. +It is a \textit{lunch} and it takes $15$ minutes of preparation. +\end{itemize} + +% ================================= % +\newpage +\section*{Part 2: A Handful of Helpful Functions} + +Create a series of useful functions to handle your \texttt{cookbook}: + +\begin{enumerate} + \item A function that prints all recipe names. + \item A function that takes a recipe name and prints its details. + \item A function that takes a recipe name and delete it. + \item A function that adds a recipe from user input. You will need a name, a list of ingredients, a meal type and a preparation time. +\end{enumerate} +\subsection*{Input example} +\begin{42console} +>>> Enter a name: +chips +>>> Enter ingredients: +potatoes +oil +salt + +>>> Enter a meal type: +lunch +>>> Enter a preparation time: +15 +\end{42console} + +% ================================= % +\section*{Part 3: A command line executable !} + +Create a program that uses your \texttt{cookbook} and your functions.\\ +\newline +The program will prompt the user to make a choice between printing the cookbook's content, + printing one recipe, adding a recipe, deleting a recipe or quitting the cookbook.\\ +\newline +Your program will continue to prompt the user until the user decides to quit it.\\ +\newline +The program cannot crash if a wrong value is entered: you must handle the error and ask for another prompt.\\ + +\begin{42console} +$> python3 recipe.py +Welcome to the Python Cookbook ! +List of available options: + 1: Add a recipe + 2: Delete a recipe + 3: Print a recipe + 4: Print the cookbook + 5: Quit + +Please select an option: +>> 3 + +Please enter a recipe name to get its details: +>> cake + +Recipe for cake: + Ingredients list: ['flour', 'sugar', 'eggs'] + To be eaten for dessert. + Takes 60 minutes of cooking. + +Please select an option: +>> Hello + +Sorry, this option does not exist. +List of available options: + 1: Add a recipe + 2: Delete a recipe + 3: Print a recipe + 4: Print the cookbook + 5: Quit + +Please select an option: +>> 5 + +Cookbook closed. Goodbye ! +$> +\end{42console} \ No newline at end of file diff --git a/module00/subject/exercises/m00ex07.tex b/module00/subject/exercises/m00ex07.tex new file mode 100644 index 00000000..857af2dd --- /dev/null +++ b/module00/subject/exercises/m00ex07.tex @@ -0,0 +1,32 @@ +\chapter{Exercise 07} +\extitle{Shorter, Faster ... Pythonic !} +\turnindir{ex07} +\exnumber{07} +\exfiles{filterwords.py} +\exforbidden{filter} +\makeheaderfilesforbidden +Make a program that takes a string S and an integer N as argument and prints the list of words in S that contains more than N non-punctuation characters. + +\begin{itemize} + \item Words are separated from each other by space characters + \item Punctuation symbols must be removed from the printed list: they are neither part of a word nor a separator + \item The program must contain at least one \textbf{list comprehension} expression. +\end{itemize} +If the number of argument is different from 2, or if the type of any argument is invalid, the program prints an error message. + +\section*{Examples} +\begin{42console} +$> python3 filterwords.py 'Hello, my friend' 3 +['Hello', 'friend'] +$> python3 filterwords.py 'Hello, my friend' 10 +[] +$> python3 filterwords.py 'A robot must protect its own existence as long as such protection does not conflict with the First or Second Law' 6 +['protect', 'existence', 'protection', 'conflict'] +$> python3 filterwords.py Hello World +ERROR +$> python3 filterwords.py 3 'Hello, my friend' +ERROR +$> python3 filterwords.py +ERROR +\end{42console} + \ No newline at end of file diff --git a/module00/subject/exercises/m00ex08.tex b/module00/subject/exercises/m00ex08.tex new file mode 100644 index 00000000..903231ec --- /dev/null +++ b/module00/subject/exercises/m00ex08.tex @@ -0,0 +1,34 @@ +\chapter{Exercise 08} +\extitle{S.O.S} +\turnindir{ex08} +\exnumber{08} +\exfiles{sos.py} +\exforbidden{None} +\makeheaderfilesforbidden +Make a program that takes a string as argument and encodes it into Morse code. +\begin{itemize} + \item The program supports space and alphanumeric characters + \item An alphanumeric character is represented by dots \texttt{.} and dashes \texttt{-} + \item A space character is represented by a slash \texttt{/} + \item Complete morse characters are separated by a single space\\ +\end{itemize} +If more than one argument is provided, merge them into a single string with each argument separated by a single space character.\\ +\newline +If no argument is provided, do nothing or print an usage. + +% ================================= % +\section*{Examples} +\begin{42console} + $> python3 sos.py "SOS" + ... --- ... + $> python3 sos.py + $> python3 sos.py "HELLO / WORLD" + ERROR + + $> python3 sos.py "96 BOULEVARD" "Bessiere" + ----. -.... / -... --- ..- .-.. . ...- .- .-. -.. / -... . ... ... .. . .-. . +\end{42console} + +\hint{ + \url{https://morsecode.world/international/morse2.html} +} \ No newline at end of file diff --git a/module00/subject/exercises/m00ex09.aux b/module00/subject/exercises/m00ex09.aux new file mode 100644 index 00000000..0eb3231d --- /dev/null +++ b/module00/subject/exercises/m00ex09.aux @@ -0,0 +1,43 @@ +\relax +\providecommand\zref@newlabel[2]{} +\providecommand\hyper@newdestlabel[2]{} +\@writefile{toc}{\contentsline {chapter}{\numberline {XI}Exercise 09}{20}{chapter.11}\protected@file@percent } +\@writefile{lof}{\addvspace {10\p@ }} +\@writefile{lot}{\addvspace {10\p@ }} +\@setckpt{exercises/m00ex09}{ +\setcounter{page}{22} +\setcounter{equation}{0} +\setcounter{enumi}{4} +\setcounter{enumii}{0} +\setcounter{enumiii}{0} +\setcounter{enumiv}{0} +\setcounter{footnote}{0} +\setcounter{mpfootnote}{0} +\setcounter{part}{0} +\setcounter{chapter}{11} +\setcounter{section}{0} +\setcounter{subsection}{0} +\setcounter{subsubsection}{0} +\setcounter{paragraph}{0} +\setcounter{subparagraph}{0} +\setcounter{figure}{0} +\setcounter{table}{0} +\setcounter{lstnumber}{10} +\setcounter{section@level}{0} +\setcounter{Item}{4} +\setcounter{Hfootnote}{0} +\setcounter{bookmark@seq@number}{11} +\setcounter{float@type}{16} +\setcounter{lofdepth}{1} +\setcounter{lotdepth}{1} +\setcounter{FancyVerbLine}{0} +\setcounter{listing}{0} +\setcounter{mdf@globalstyle@cnt}{0} +\setcounter{mdfcountframes}{0} +\setcounter{mdf@env@i}{0} +\setcounter{mdf@env@ii}{0} +\setcounter{mdf@zref@counter}{0} +\setcounter{exerciceCounter}{12} +\setcounter{itemizeCounter}{0} +\setcounter{lstlisting}{0} +} diff --git a/module00/subject/exercises/m00ex09.tex b/module00/subject/exercises/m00ex09.tex new file mode 100644 index 00000000..8080ca69 --- /dev/null +++ b/module00/subject/exercises/m00ex09.tex @@ -0,0 +1,73 @@ +\chapter{Exercise 09} +\extitle{Secret number} +\turnindir{ex09} +\exnumber{09} +\exfiles{guess.py} +\exforbidden{None} +\makeheaderfilesforbidden +You have to make a program that will be an interactive guessing game.\\ +\newline +It will prompt the user to guess a number between $1$ and $99$. The program will tell the user if their +input is too high or too low. +\newline +The game ends when the user finds out the secret number or types \texttt{exit}.\\ +\newline +You will import the \texttt{random} module with the \texttt{randint} function to get a random number. +You have to count the number of trials and print that number when the user wins. + +\section*{Examples} +\begin{42console} +$> python guess.py +This is an interactive guessing game! +You have to enter a number between 1 and 99 to find out the secret number. +Type 'exit' to end the game. +Good luck! + +What's your guess between 1 and 99? +>> 54 +Too high! +What's your guess between 1 and 99? +>> 34 +Too low! +What's your guess between 1 and 99? +>> 45 +Too high! +What's your guess between 1 and 99? +>> A +That's not a number. +What's your guess between 1 and 99? +>> 43 +Congratulations, you've got it! +You won in 5 attempts! +\end{42console} +If the user discovers the secret number on the first try, tell them !\\ +\newline +If the secret number is 42, make a reference to Douglas Adams.\\ +\newline + +\begin{42console} + $> python guess.py + This is an interactive guessing game! + You have to enter a number between 1 and 99 to find out the secret number. + Type 'exit' to end the game. + Good luck! + + What's your guess between 1 and 99? + >> 42 + The answer to the ultimate question of life, the universe and everything is 42. + Congratulations! You got it on your first try! +\end{42console} + +Other example: + +\begin{42console} + $> python guess.py + This is an interactive guessing game! + You have to enter a number between 1 and 99 to find out the secret number. + Type 'exit' to end the game. + Good luck! + + What's your guess between 1 and 99? + >> exit + Goodbye! +\end{42console} diff --git a/module00/subject/exercises/m00ex10.aux b/module00/subject/exercises/m00ex10.aux new file mode 100644 index 00000000..87f6dc37 --- /dev/null +++ b/module00/subject/exercises/m00ex10.aux @@ -0,0 +1,43 @@ +\relax +\providecommand\zref@newlabel[2]{} +\providecommand\hyper@newdestlabel[2]{} +\@writefile{toc}{\contentsline {chapter}{\numberline {XII}Exercise 10}{22}{chapter.12}\protected@file@percent } +\@writefile{lof}{\addvspace {10\p@ }} +\@writefile{lot}{\addvspace {10\p@ }} +\@setckpt{exercises/m00ex10}{ +\setcounter{page}{24} +\setcounter{equation}{0} +\setcounter{enumi}{4} +\setcounter{enumii}{0} +\setcounter{enumiii}{0} +\setcounter{enumiv}{0} +\setcounter{footnote}{0} +\setcounter{mpfootnote}{0} +\setcounter{part}{0} +\setcounter{chapter}{12} +\setcounter{section}{0} +\setcounter{subsection}{0} +\setcounter{subsubsection}{0} +\setcounter{paragraph}{0} +\setcounter{subparagraph}{0} +\setcounter{figure}{0} +\setcounter{table}{0} +\setcounter{lstnumber}{5} +\setcounter{section@level}{0} +\setcounter{Item}{4} +\setcounter{Hfootnote}{0} +\setcounter{bookmark@seq@number}{12} +\setcounter{float@type}{16} +\setcounter{lofdepth}{1} +\setcounter{lotdepth}{1} +\setcounter{FancyVerbLine}{0} +\setcounter{listing}{0} +\setcounter{mdf@globalstyle@cnt}{0} +\setcounter{mdfcountframes}{0} +\setcounter{mdf@env@i}{0} +\setcounter{mdf@env@ii}{0} +\setcounter{mdf@zref@counter}{0} +\setcounter{exerciceCounter}{12} +\setcounter{itemizeCounter}{0} +\setcounter{lstlisting}{0} +} diff --git a/module00/subject/exercises/m00ex10.tex b/module00/subject/exercises/m00ex10.tex new file mode 100644 index 00000000..cb206f06 --- /dev/null +++ b/module00/subject/exercises/m00ex10.tex @@ -0,0 +1,49 @@ +\chapter{Exercise 10} +\extitle{Loading bar!} +\turnindir{ex10} +\exnumber{10} +\exfiles{loading.py} +\exforbidden{\texttt{tqdm} or any library for automatic loading bar} +\makeheaderfilesforbidden +You are about to discover the \texttt{yield} operator!\\ +\newline +So let's create a function called \texttt{ft\_progress(lst)}.\\ +\newline +The function will display the progress of a \texttt{for} loop.\\ +\info{We strongly advise you to take a look at the wonderful \textbf{tqdm} library, it will come in handy in many situations !} +\section*{Examples} +\begin{42console}% SERAIT MIEUX AVEC UN ENVIRONNEMENT PYTHON + listy = range(1000) + ret = 0 + for elem in ft_progress(listy): + ret += (elem + 3) % 5 + sleep(0.01) + print() + print(ret) +\end{42console} + +\begin{42console} + $> python loading.py + ETA: 8.67s [ 23%][=====> ] 233/1000 | elapsed time 2.33s + ... + 2000 +\end{42console} +\newpage +\begin{42console}% SERAIT MIEUX AVEC UN ENVIRONNEMENT PYTHON + listy = range(3333) + ret = 0 + for elem in ft_progress(listy): + ret += elem + sleep(0.005) + print() + print(ret) +\end{42console} + +\begin{42console} + $> python loading.py + ETA: 14.67s [ 9%][=> ] 327/3333 | elapsed time 1.33s + ... + 5552778 +\end{42console} + + diff --git a/module01/exercises/m01ex00.tex b/module01/exercises/m01ex00.tex new file mode 100644 index 00000000..aefeb823 --- /dev/null +++ b/module01/exercises/m01ex00.tex @@ -0,0 +1,87 @@ +\chapter{Exercise 00} +\extitle{The Book} +\turnindir{ex00} +\exnumber{00} +\exfiles{book.py, recipe.py, test.py} +\exforbidden{None} +\makeheaderfilesforbidden + +% ================================== % +\section*{Objective} +% ---------------------------------- % +The goal of this exercise is to get you familiar with the notions of +classes and the manipulation of the objects related to these classes. + +% ================================== % +\section*{Instructions} +% ---------------------------------- % +You will have to make a class \texttt{Book} and a class \texttt{Recipe}. +The classes \texttt{Book} and \texttt{Recipe} will be written in +\texttt{book.py} and \texttt{recipe.py} respectively.\\ +\newline +Let's describe the \texttt{Recipe} class. It has some attributes: +\begin{itemize} + \item \texttt{name} (str): name of the recipe, + \item \texttt{cooking\_lvl} (int): range from $1$ to $5$, + \item \texttt{cooking\_time} (int): in minutes (no negative numbers), + \item \texttt{ingredients} (list): list of all ingredients each represented by a string, + \item \texttt{description} (str): description of the recipe, + \item \texttt{recipe\_type} (str): can be "starter", "lunch" or "dessert". +\end{itemize} +You have to \textbf{initialize} the object \texttt{Recipe} and check all of its values. Only the description can be empty. +In case of input errors, you should print what they are and exit properly.\\ +\newline +You will have to implement the built-in method \texttt{\_\_str\_\_}. +It's the method called when the following code is executed:\\ +\newline +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} +tourte = Recipe(...) +to_print = str(tourte) +print(to_print) +\end{minted} +\newline +\newline +It is implemented this way:\\ +\newline +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} +def __str__(self): + """Returns the string to print with the recipe's info""" + txt = "" + """Your code here""" + return txt +\end{minted} +\newline +The \texttt{Book} class also has some attributes: +\begin{itemize} + \item \texttt{name} (str): name of the book, + \item \texttt{last\_update} \href{https://docs.python.org/3/library/datetime.html}{(datetime)}: the date of the last update, + \item \texttt{creation\_date} \href{https://docs.python.org/3/library/datetime.html}{(datetime)}: the creation date of the book, + \item \texttt{recipes\_list} (dict): a dictionnary with 3 keys: "starter", "lunch", "dessert". +\end{itemize} +You will have to implement some methods in the \texttt{Book} class:\\ +\newline +\begin{minted}[bgcolor=darcula-back ,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} +def get_recipe_by_name(self, name): + """Prints a recipe with the name \texttt{name} and returns the instance""" + #... Your code here ... + +def get_recipes_by_types(self, recipe_type): + """Gets all recipes names for a given recipe_type """ + #... Your code here ... + +def add_recipe(self, recipe): + """Adds a recipe to the book and updates last_update""" + #... Your code here ... +\end{minted} +\newline +You have to handle the error if the argument passed in \texttt{add\_recipe} is not a \texttt{Recipe}.\\ +\newline +Finally, you will provide a \texttt{test.py} file to test your classes and prove that they are working properly. +You can import all the classes into your \texttt{test.py} file by adding these lines at the top of the \texttt{test.py} file:\\ +\newline +\begin{minted}[bgcolor=darcula-back ,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} +from book import Book +from recipe import Recipe + +# ... Your tests ... +\end{minted} \ No newline at end of file diff --git a/module01/exercises/m01ex01.tex b/module01/exercises/m01ex01.tex new file mode 100644 index 00000000..ba50f1d3 --- /dev/null +++ b/module01/exercises/m01ex01.tex @@ -0,0 +1,76 @@ +\chapter{Exercise 01} +\extitle{Family tree} +\turnindir{ex01} +\exnumber{01} +\exfiles{game.py} +\exforbidden{None} +\makeheaderfilesforbidden + +% ================================= % +\section*{Objective} +% --------------------------------- % +The goal of the exercise is to tackle the notion of class inheritance. + +% ================================= % +\section*{Instructions} +% --------------------------------- % +Create a \texttt{GotCharacter} class and initialize it with the following attributes: +\begin{itemize} + \item \texttt{first\_name}, + \item \texttt{is\_alive} (by default is \texttt{True}). +\end{itemize} +Pick up a Game of Thrones House (e.g., Stark, Lannister...), create a child class that inherits from \texttt{GotCharacter} and +define the following attributes: +\begin{itemize} + \item \texttt{family\_name} (by default should be the same as the Class) + \item \texttt{house\_words} (e.g., the House words for the Stark House is: "Winter is Coming")\\ +\end{itemize} +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} + class Stark(GotCharacter): + def __init__(self, first_name=None, is_alive=True): + super().__init__(first_name=first_name, is_alive=is_alive) + self.family_name = "Stark" + self.house_words = "Winter is Coming" +\end{minted} + +\newpage +Add two methods to your child class: +\begin{itemize} + \item \texttt{print\_house\_words}: prints the House words, + \item \texttt{die}: changes the value of \texttt{is\_alive} to \texttt{False}. +\end{itemize} + +\section*{Examples} +Running commands in the Python console, an example of what you should get:\\ +\newline + +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} + $> python + >>> from game import Stark + + >>> arya = Stark("Arya") + >>> print(arya.__dict__) + {'first_name': 'Arya', 'is_alive': True, 'family_name': 'Stark', 'house_words': 'Winter is Coming'} + + >>> arya.print_house_words() + Winter is Coming + + >>> print(arya.is_alive) + True + + >>> arya.die() + >>> print(arya.is_alive) + False +\end{minted} +\newline +You can add any attribute or method you need to your class and format the docstring the way you want. +Feel free to create other children of \texttt{GotCharacter} class. +\newline +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} + $> python + >>> from game import Stark + + >>> arya = Stark("Arya") + >>> print(arya.__doc__) + A class representing the Stark family. Or when bad things happen to good people. +\end{minted} \ No newline at end of file diff --git a/module01/exercises/m01ex02.tex b/module01/exercises/m01ex02.tex new file mode 100644 index 00000000..4aa91a23 --- /dev/null +++ b/module01/exercises/m01ex02.tex @@ -0,0 +1,239 @@ +\chapter{Exercise 02} +\extitle{The Vector} +\turnindir{ex02} +\exnumber{02} +\exfiles{vector.py, test.py} +\exforbidden{Numpy library} +\makeheaderfilesforbidden + +% ================================= % +\section*{Objective} +% --------------------------------- % +The goal of this exercise is to get you used to working with built-in methods, more +particularly with those allowing to perform operations. +You are expected to code built-in methods for vector-vector and +vector-scalar operations as rigorously as possible. + +% ================================= % +\section*{Instructions} +% --------------------------------- % +In this exercise, you have to create a \texttt{Vector} class. The goal is to +create vectors and be able to perform mathematical operations with them. +\begin{itemize} + \item Column vectors are represented as list of lists of single float (\texttt{[[1.], [2.], [3.]]}), + \item Row vectors are represented as a list of a list of several floats (\texttt{[[1., 2., 3.]]}). +\end{itemize} + +\warn{A vector is either a single line of floats or a single column of floats. When more than a line/column is considered, it is a matrix, not a vector.} + + +The class should also have 2 attributes: +\begin{itemize} + \item \texttt{values}: list of list of floats (for row vector) or list of lists of single float (for column vector), + \item \texttt{shape}: tuple of 2 integers: \texttt{(1,n)} for a row vector of dimension $n$ + or \texttt{(n,1)} for a column vector of dimension $n$. +\end{itemize} + +\info{If you did not learn at school what is the dimension of a vector, don't worry. +But for now do not think too hard about what dimension means. +Just consider the dimension is the number of floats (elements/coordinates) of a vector, and shape gives the layout: + if $(1, n)$ the vector is a row, if $(n,1)$ the vector is a column.} + +Finally you have to implement 2 methods: +\begin{itemize} + \item \texttt{.dot()} produces a dot product between two vectors of same \textbf{shape}, + \item \texttt{.T()} returns the transpose vector (i.e. a column vector into a row vector, or a row vector into a column vector). +\end{itemize} + +You will also provide a test file (\texttt{test.py}) to demonstrate your class +works as expected. In this test file, you will demonstrate: +\begin{itemize} + \item the addition and substraction are working for 2 vectors of the same shape, + \item the multiplication (\texttt{mul} and \texttt{rmul}) are working for a vector and a scalar, + \item the division (\texttt{truediv}) is working with a vector and a scalar, + \item the division (\texttt{rtruediv}) raises an Arithmetic Error (this test can be commented for the other tests and uncommented to show this one), +\end{itemize} + +\section*{Examples} +% --------------------------------- % +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} +# Column vector of shape n * 1 +v1 = Vector([[0.0], [1.0], [2.0], [3.0]]) +v2 = v1 * 5 +print(v2) +# Expected output: +# Vector([[0.0], [5.0], [10.0], [15.0]]) + +# Row vector of shape 1 * n +v1 = Vector([[0.0, 1.0, 2.0, 3.0]]) +v2 = v1 * 5 +print(v2) +# Expected output +# Vector([[0.0, 5.0, 10.0, 15.0]]) + +v2 = v1 / 2.0 +print(v2) +# Expected output +# Vector([[0.0, 0.5, 1.0, 1.5]]) + +v1 / 0.0 +# Expected ouput +# ZeroDivisionError: division by zero. + +2.0 / v1 +# Expected output: +# NotImplementedError: Division of a scalar by a Vector is not defined here. +\end{minted} + +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} +# Column vector of shape (n, 1) +print(Vector([[0.0], [1.0], [2.0], [3.0]]).shape) +# Expected output +# (4,1) + +print(Vector([[0.0], [1.0], [2.0], [3.0]]).values) +# Expected output +# [[0.0], [1.0], [2.0], [3.0]] + +# Row vector of shape (1, n) +print(Vector([[0.0, 1.0, 2.0, 3.0]]).shape) +# Expected output +# (1,4) + +print(Vector([[0.0, 1.0, 2.0, 3.0]]).values) +# Expected output +# [[0.0, 1.0, 2.0, 3.0]] +\end{minted} + + +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} +# Example 1: +v1 = Vector([[0.0], [1.0], [2.0], [3.0]]) +print(v1.shape) +# Expected output: +(4,1) + +print(v1.T()) +# Expected output: +# Vector([[0.0, 1.0, 2.0, 3.0]]) + +print(v1.T().shape) +# Expected output: +# (1,4) + +# Example 2: +v2 = Vector([[0.0, 1.0, 2.0, 3.0]]) +print(v2.shape) +# Expected output: +# (1,4) + +print(v2.T()) +# Expected output: +# Vector([[0.0], [1.0], [2.0], [3.0]]) + +print(v2.T().shape) +# Expected output: +# (4,1) +\end{minted} + +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} + # Example 1: + v1 = Vector([[0.0], [1.0], [2.0], [3.0]]) + v2 = Vector([[2.0], [1.5], [2.25], [4.0]]) + print(v1.dot(v2)) + # Expected output: + # 18.0 + + v3 = Vector([[1.0, 3.0]]) + v4 = Vector([[2.0, 4.0]]) + print(v3.dot(v4)) + # Expected output: + # 14.0 + + v1 + # Expected output: to see what __repr__() should do + # [[0.0, 1.0, 2.0, 3.0]] + + print(v1) + # Expected output: to see what __str__() should do + # [[0.0, 1.0, 2.0, 3.0]] +\end{minted} + +You should be able to initialize the object with: +\begin{itemize} + \item a list of a list of floats: \texttt{Vector([[0.0, 1.0, 2.0, 3.0]])}, + \item a list of lists of single float: \texttt{Vector([[0.0], [1.0], [2.0], [3.0]])}, + \item a size: \texttt{Vector(3)} -> the vector will have \texttt{values = [[0.0], [1.0], [2.0]]}, + \item a range: \texttt{Vector((10,16))} -> the vector will have \texttt{values = [[10.0], [11.0], [12.0], [13.0], [14.0], [15.0]]}. + in \texttt{Vector((a,b))}, if \texttt{a > b}, you must display accurate error message. +\end{itemize} + +\textit{By default, the vectors are generated as classical column vectors if initialized with a size or range.} + +To perform arithmetic operations for Vector-Vector or Scalar-Vector, you have to implement all the following built-in functions (called \texttt{magic/special methods}) for your \texttt{Vector} class: + +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} + __add__ + __radd__ + # add & radd : only vectors of the same shape. + __sub__ + __rsub__ + # sub & rsub: only vectors of the same shape. + __truediv__ + # truediv : only with scalars (to perform division of a Vector by a scalar). + __rtruediv__ + # rtruediv : raises an NotImplementedError with the message "Division of a scalar by a Vector is not defined here." + __mul__ + __rmul__ + # mul & rmul: only scalars (to perform multiplication of a Vector by a scalar). + __str__ + __repr__ + # must be identical, i.e we expect that print(vector) and vector within python interpretor to behave the same, see corresponding example section. +\end{minted} + +\info{ + So it might be a good idea to implement \texttt{values} and \texttt{shape} before built-in arithmetic functions. + For the case not specified (e.g vector * vector) you should raise \texttt{NotImplementedError}. +} + + +% ================================= % +\section*{Mathematic notions} +% --------------------------------- % +The authorized vector operations are: + +\begin{itemize} + \item Addition between two vectors of same dimension $m$ + \begin{equation*} + x + y = + \begin{bmatrix} x_1 \\ \vdots \\ x_m\end{bmatrix} + + \begin{bmatrix} y_1 \\ \vdots \\ y_m\end{bmatrix} \\ + = \begin{bmatrix} x_1 + y_1 \\ \vdots \\ x_m + y_m \end{bmatrix} + \end{equation*} + \item Substraction between two vectors of same dimension $m$ + \begin{equation*} + x - y = + \begin{bmatrix} x_1 \\ \vdots \\ y_m\end{bmatrix} - + \begin{bmatrix} x_1 \\ \vdots \\ y_m\end{bmatrix} + = \begin{bmatrix} x_1 - y_1 \\ \vdots \\ x_m - y_m \end{bmatrix} + \end{equation*} + \item Multiplication and division between one vector $m$ and one scalar. + \begin{equation*} + \alpha x = \alpha \begin{bmatrix} x_1 \\ \vdots \\ x_m\end{bmatrix} = + \begin{bmatrix} \alpha x_1 \\ \vdots \\ \alpha x_m \end{bmatrix} + \end{equation*} + \item Dot product between two vectors of same dimension $m$ + \begin{equation*} + x \cdot y = \begin{bmatrix} x_1 \\ \vdots \\ x_m\end{bmatrix} + \cdot + \begin{bmatrix} y_1 \\ \vdots \\ y_m\end{bmatrix} = + \sum_{i = 1}^{m} x_i \cdot y_i = x_1 \cdot y_1 + \dots + x_m \cdot y_m + \end{equation*} +\end{itemize} + +Do not forget to handle all types of error properly! + + +% ===========================(fin ex 02) % +% ============================================== % + diff --git a/module01/exercises/m01ex03.tex b/module01/exercises/m01ex03.tex new file mode 100644 index 00000000..d6429dc0 --- /dev/null +++ b/module01/exercises/m01ex03.tex @@ -0,0 +1,99 @@ +\chapter{Exercise 03} +\extitle{Generator!} +\turnindir{ex03} +\exnumber{03} +\exfiles{generator.py} +\exauthorize{random.randint, random.choice} +\exforbidden{random.shuffle, random.sample} +\makeheaderfilesforbidden + + +% ================================= % +\section*{Objective} +% --------------------------------- % +The goal of this exercise is to discover the concept of generator object in Python. + +% ================================= % +\section*{Instructions} +% --------------------------------- % +Code a function called \texttt{generator} that takes a text as input (only printable characters), uses the string +parameter \texttt{sep} as a splitting parameter, and \texttt{yield}s the resulting substrings. + +The function can take an optional argument. +The options are: +\begin{itemize} + \item \texttt{shuffle}: shuffles the list of words, + \item \texttt{unique}: returns a list where each word appears only once, + \item \texttt{ordered}: sorts the words alphabetically. +\end{itemize} + +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} + # function prototype + def generator(text, sep=" ", option=None): + ''' + Splits the text according to sep value and yields the substrings. + ''' +\end{minted} + +You can only call one option at a time. + +% ================================= % +\section*{Examples} +% --------------------------------- % +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} + >> text = "Le Lorem Ipsum est simplement du faux texte." + >> for word in generator(text, sep=" "): + ... print(word) + ... + Le + Lorem + Ipsum + est + simplement + du + faux + texte. + + >> for word in generator(text, sep=" ", option="shuffle"): + ... print(word) + ... + simplement + texte. + est + faux + Le + Lorem + Ipsum + du + + >> for word in generator(text, sep=" ", option="ordered"): + ... print(word) + ... + Ipsum + Le + Lorem + du + est + faux + simplement + texte. +\end{minted} + +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} +>> text = "Lorem Ipsum Lorem Ipsum" +>> for word in generator(text, sep=" ", option="unique"): +... print(word) +... +Lorem +Ipsum +\end{minted} + +The function should return "ERROR" one time if the \texttt{text} argument is not a string, or if the \texttt{option} argument is not valid. + +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} +>> text = 1.0 +>> for word in generator(text, sep="."): +... print(word) +... +ERROR +\end{minted} \ No newline at end of file diff --git a/module01/exercises/m01ex04.tex b/module01/exercises/m01ex04.tex new file mode 100644 index 00000000..dd3f4ace --- /dev/null +++ b/module01/exercises/m01ex04.tex @@ -0,0 +1,49 @@ +\chapter{Exercise 04} +\extitle{Working with lists} +\turnindir{ex04} +\exnumber{04} +\exfiles{eval.py} +\exauthorize{zip and enumerate} +\exforbidden{while} +\makeheaderfilesforbidden + + +% ================================= % +\section*{Objective} +% --------------------------------- % +The goal of this exercise is to discover 2 useful methods for lists, tuples, +dictionnaries (iterable class objects more generally) named \texttt{zip} +and \texttt{enumerate}. + +% ================================= % +\section*{Instructions} +% --------------------------------- % +Code a class \texttt{Evaluator}, that has two static functions named \texttt{zip\_evaluate} +and \texttt{enumerate\_evaluate}. + + +The goal of these 2 functions is to compute the sum of the lengths of every +\texttt{words} of a given list weighted by a list of coefficients \texttt{coefs} (yes, the 2 functions should do the same thing). + +The lists \texttt{coefs} and \texttt{words} have to be of the same length. If this is not the +case, the function should return -1. + +You have to obtain the desired result using \texttt{zip} in the \texttt{zip\_evaluate} function, +and with \texttt{enumerate} in the \texttt{enumerate\_evaluate} function. + +% ================================= % +\section*{Examples} +% --------------------------------- % +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} +>> from eval import Evaluator +>> +>> words = ["Le", "Lorem", "Ipsum", "est", "simple"] +>> coefs = [1.0, 2.0, 1.0, 4.0, 0.5] +>> Evaluator.zip_evaluate(coefs, words) +32.0 +>> words = ["Le", "Lorem", "Ipsum", "n'", "est", "pas", "simple"] +>> coefs = [0.0, -1.0, 1.0, -12.0, 0.0, 42.42] +>> Evaluator.enumerate_evaluate(coefs, words) +-1 +\end{minted} + diff --git a/module01/exercises/m01ex05.tex b/module01/exercises/m01ex05.tex new file mode 100644 index 00000000..9715545b --- /dev/null +++ b/module01/exercises/m01ex05.tex @@ -0,0 +1,145 @@ +\chapter{Exercise 05} +\extitle{Bank Account} +\turnindir{ex05} +\exnumber{05} +\exfiles{the\_bank.py} +\exforbidden{None} +\makeheaderfilesforbidden + +% ================================= % +\section*{Objective} +% --------------------------------- % +The goal of this exercise is to discover new built-in functions, +deepen your class understanding, and to be aware of modifications on +instanced objects.\\ +In this exercise, you will learn how to modify or add attributes to an object. + +% ================================= % +\section*{Instructions} +% --------------------------------- % +It is all about security. +Have a look at the class named \texttt{Account} in the code snippet below. + +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} +# in the_bank.py +class Account(object): + + ID_COUNT = 1 + + def __init__(self, name, **kwargs): + self.__dict__.update(kwargs) + + self.id = self.ID_COUNT + Account.ID_COUNT += 1 + self.name = name + if not hasattr(self, 'value'): + self.value = 0 + + if self.value < 0: + raise AttributeError("Attribute value cannot be negative.") + if not isinstance(self.name, str) + raise AttributeError("Attribute name must be a str object.") + + def transfer(self, amount): + self.value += amount +\end{minted} + +Now, it is your turn to code a class named \texttt{Bank}! +Its purpose will be to handle the security part of each transfer attempt. + +Security means checking if the \texttt{Account} is: +\begin{itemize} + \item the right object, + \item not corrupted, + \item and stores enough money to complete the transfer. +\end{itemize} + +How do we define if a bank account is corrupted? A corrupted bank account has: +\begin{itemize} + \item an even number of attributes, + \item an attribute starting with \texttt{b}, + \item no attribute starting with \texttt{zip} or \texttt{addr}, + \item no attribute \texttt{name}, \texttt{id} and \texttt{value}, + \item \texttt{name} not being a string, + \item \texttt{id} not being an \texttt{int}, + \item \texttt{value} not being an \texttt{int} or a \texttt{float}. +\end{itemize} + +For the rest of the attributes (\texttt{addr}, \texttt{zip}, etc ... +there is no specific check expected. +Meaning you are not expected to evaluate the validity of the account based on the type of the other attributes (the conditions listed above are sufficient). + +Moreover, verification has to be performed when account objects are added to to Bank instance +(\texttt{bank.add(Account(...))}). +The verification in \texttt{add} only checsk the type of the new\_account and if there +is no account among the ones already in Bank instance with the same name. + +A transaction is invalid if \texttt{amount < 0} or if the amount is larger than +the balance of the account. +Prior to the transfer, the validity of the 2 accounts (\texttt{origin} and \texttt{dest}) are checked +(according to the list of criteria above). +A transfer between the same account (\texttt{bank.transfer('Wiliam John', 'William John')}) +is valid but there is no fund movement. + +\texttt{fix\_account} recovers a corrupted account if it parameter \texttt{name} correspond to the attribute +name of one of the account in \texttt{accounts} (attribute of Bank). If name is not a string or does not corresponded +to an account name, the method return \texttt{False}. + +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} +# in the_bank.py +class Bank(object): + """The bank""" + def __init__(self): + self.accounts = [] + + def add(self, new_account): + """ Add new_account in the Bank + @new_account: Account() new account to append + @return True if success, False if an error occured + """ + # test if new_account is an Account() instance and if + # it can be appended to the attribute accounts + + # ... Your code ... + + self.accounts.append(new_account) + + def transfer(self, origin, dest, amount): + """" Perform the fund transfer + @origin: str(name) of the first account + @dest: str(name) of the destination account + @amount: float(amount) amount to transfer + @return True if success, False if an error occured + """ + # ... Your code ... + + def fix_account(self, name): + """ fix account associated to name if corrupted + @name: str(name) of the account + @return True if success, False if an error occured + """ + # ... Your code ... +\end{minted} + +Check out the \texttt{dir} built-in function. + +\warn{YOU WILL HAVE TO MODIFY THE INSTANCES' ATTRIBUTES IN ORDER TO FIX THEM.} + +% ================================= % +\section*{Examples} +% --------------------------------- % +The script \texttt{banking\_test1.py} is a test which must print \texttt{Failed}. +The second script \texttt{banking\_test2.py} is a test which must print \texttt{Failed} and then \texttt{Success}. + +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{bash} +>> python banking_test1.py +Failed +# The transaction is not performed has the account of Smith Jane is corrupted (due to the attribute 'bref'). + +>> python banking_test2.py +Failed +Success +# the account are false due to the abscence of addr attribute, fix_account recover the account, +# thus they become valid. +\end{minted} + diff --git a/module01/exercises/m01ex06.tex b/module01/exercises/m01ex06.tex new file mode 100644 index 00000000..e69de29b diff --git a/module01/exercises/m01ex07.tex b/module01/exercises/m01ex07.tex new file mode 100644 index 00000000..e69de29b diff --git a/module01/exercises/m01ex08.tex b/module01/exercises/m01ex08.tex new file mode 100644 index 00000000..e69de29b diff --git a/module01/subject/assets/42ai_logo.pdf b/module01/subject/assets/42ai_logo.pdf index c915fc5c..1f5d3abb 100644 Binary files a/module01/subject/assets/42ai_logo.pdf and b/module01/subject/assets/42ai_logo.pdf differ diff --git a/module01/subject/en.acknowledgements.tex b/module01/subject/en.acknowledgements.tex new file mode 100644 index 00000000..6737d884 --- /dev/null +++ b/module01/subject/en.acknowledgements.tex @@ -0,0 +1,38 @@ +\section*{Contact} +% --------------------------------- % +You can contact 42AI by email: \href{mailto:contact@42ai.fr}{contact@42ai.fr}\\ +\newline +Thank you for attending 42AI's Python Bootcamp module01 ! + +% ================================= % +\section*{Acknowledgements} +% --------------------------------- % +The Python bootcamp is the result of a collective work, for which we would like to thank: +\begin{itemize} + \item Maxime Choulika (cmaxime), + \item Pierre Peigné (ppeigne, pierre@42ai.fr), + \item Matthieu David (mdavid, matthieu@42ai.fr), + \item Quentin Feuillade--Montixi (qfeuilla, quentin@42ai.fr) + \item Mathieu Perez (maperez, mathieu.perez@42ai.fr) +\end{itemize} +who supervised the creation, the enhancement of the bootcamp and this present transcription. + +\begin{itemize} + \item Louis Develle (ldevelle, louis@42ai.fr) + \item Augustin Lopez (aulopez) + \item Luc Lenotre (llenotre) + \item Owen Roberts (oroberts) + \item Thomas Flahault (thflahau) + \item Amric Trudel (amric@42ai.fr) + \item Baptiste Lefeuvre (blefeuvr@student.42.fr) + \item Mathilde Boivin (mboivin@student.42.fr) + \item Tristan Duquesne (tduquesn@student.42.fr) +\end{itemize} +for your investment in the creation and development of these modules. + +\begin{itemize} + \item All prior participants who took a moment to provide their feedbacks, and help us improve these bootcamps ! +\end{itemize} + + \vfill +\doclicenseThis \ No newline at end of file diff --git a/module01/subject/en.instructions.tex b/module01/subject/en.instructions.tex new file mode 100644 index 00000000..dde484d5 --- /dev/null +++ b/module01/subject/en.instructions.tex @@ -0,0 +1,36 @@ +\chapter{Common Instructions} +\begin{itemize} + \item The version of Python recommended to use is 3.7, you can + check the version of Python with the following command: \texttt{python -V} + + \item The norm: during this bootcamp, it is recommended to follow the + \href{https://www.python.org/dev/peps/pep-0008/}{PEP 8 standards}, though it is not mandatory. + You can install \href{https://pypi.org/project/pycodestyle}{pycodestyle} which + is a tool to check your Python code. + \item The function \texttt{eval} is never allowed. + \item The exercises are ordered from the easiest to the hardest. + \item Your exercises are going to be evaluated by someone else, + so make sure that your variable names and function names are appropriate and civil. + \item Your manual is the internet. + + \item If you are a student from 42, you can access our Discord server + on \href{https://discord.com/channels/887850395697807362/887850396314398720}{42 student's associations portal} and ask your + questions to your peers in the dedicated Bootcamp channel. + + \item You can learn more about 42 Artificial Intelligence by visiting \href{https://42-ai.github.io}{our website}. + + \item If you find any issue or mistake in the subject please create an issue on \href{https://github.com/42-AI/bootcamp_python/issues}{42AI repository on Github}. + + \item We encourage you to create test programs for your + project even though this work \textbf{won't have to be + submitted and won't be graded}. It will give you a chance + to easily test your work and your peers’ work. You will find + those tests especially useful during your defence. Indeed, + during defence, you are free to use your tests and/or the + tests of the peer you are evaluating. + + \item We are constantly looking to improve these bootcamps, and your feedbacks are essential for us to do so !\\ + You can tell us more about your experience with this module by filling \href{https://forms.gle/rYDeueNgBrXRfE7aA}{this form}.\\ + Thank you in advance and good luck for this bootcamp ! + +\end{itemize} \ No newline at end of file diff --git a/module01/subject/en.py_proj.tex b/module01/subject/en.py_proj.tex deleted file mode 100644 index 953d1a8b..00000000 --- a/module01/subject/en.py_proj.tex +++ /dev/null @@ -1,45 +0,0 @@ -%******************************************************************************% -% % -% Common Instructions % -% for Python Projects % -% % -%******************************************************************************% - -\chapter{Common Instructions} -\begin{itemize} - \item The version of Python recommended to use is 3.7, you can - check the version of Python with the following command: \texttt{python -V} - - \item The norm: during this bootcamp you will follow the - \href{https://www.python.org/dev/peps/pep-0008/}{PEP 8 standards}. - You can install \href{https://pypi.org/project/pycodestyle}{pycodestyle} which - is a tool to check your Python code. - - \item The function \texttt{eval} is never allowed. - - \item The exercises are ordered from the easiest to the hardest. - - \item Your exercises are going to be evaluated by someone else, - so make sure that your variable names and function names are appropriate and civil. - - \item Your manual is the internet. - - \item You can also ask questions in the \texttt{\#bootcamps} channel in the \href{https://42-ai.slack.com}{42AI} - or \href{42born2code.slack.com}{42born2code}. - - \item If you find any issue or mistakes in the subject please create an issue on \href{https://github.com/42-AI/bootcamp_python/issues}{dedicated 42AI repository on Github}. - - \item We encourage you to create test programs for your - project even though this work \textbf{won't have to be - submitted and won't be graded}. It will give you a chance - to easily test your work and your peers’ work. You will find - those tests especially useful during your defence. Indeed, - during defence, you are free to use your tests and/or the - tests of the peer you are evaluating. - - \item Submit your work to your assigned git repository. Only the work in the - git repository will be graded. If Deepthought is assigned to grade your - work, it will be run after your peer-evaluations. - If an error happens in any section of your work during Deepthought's grading, - the evaluation will stop. -\end{itemize} \ No newline at end of file diff --git a/module01/subject/en.subject.pdf b/module01/subject/en.subject.pdf new file mode 100644 index 00000000..c2f9826f Binary files /dev/null and b/module01/subject/en.subject.pdf differ diff --git a/module01/subject/en.subject.pdf.version b/module01/subject/en.subject.pdf.version deleted file mode 100644 index 56a6051c..00000000 --- a/module01/subject/en.subject.pdf.version +++ /dev/null @@ -1 +0,0 @@ -1 \ No newline at end of file diff --git a/module01/subject/en.subject.tex b/module01/subject/en.subject.tex index f64599e1..04bf5d5b 100644 --- a/module01/subject/en.subject.tex +++ b/module01/subject/en.subject.tex @@ -118,822 +118,53 @@ % =============================================================================% % ===================================== % -\title{Python \& ML - Module 01} -\subtitle{Basic 2} -\author{ - Maxime Choulika (cmaxime), Pierre Peigné (ppeigne), Matthieu David (mdavid) -} - - +\title{Python Bootcamp - Module 01} +\subtitle{Basics 2} +\author{} \summary { - The goal of the module is to get familiar with object-oriented programming - and much more. + The goal of this module is to get familiar with the Object-Oriented Programming ('OOP') + paradigm, and more ... } \maketitle -\input{en.py_proj.tex} +\input{en.instructions.tex} \newpage \tableofcontents \startexercices % ===================================== % % =============================================================================% - - %******************************************************************************% % % % Exercises % % % %******************************************************************************% - % ============================================== % % ===========================(start ex 00) % -\chapter{Exercise 00} -\extitle{The Book} -\turnindir{ex00} -\exnumber{00} -\exfiles{book.py, recipe.py, test.py} -\exforbidden{None} -\makeheaderfilesforbidden - - - -% ================================== % -\section*{Objective} -% ---------------------------------- % -The goal of the exercise is to get you familiar with the notions of -classes and the manipulation of the objects related to those classes. - -% ================================== % -\section*{Instructions} -% ---------------------------------- % -You will have to make a class \texttt{Book} and a class \texttt{Recipe}. -The classes \texttt{Book} and \texttt{Recipe} will be written in -\texttt{book.py} and \texttt{recipe.py} respectively. - - -Let's describe the \texttt{Recipe} class. It has some attributes: -\begin{itemize} - \item \texttt{name} (str): name of the recipe, - \item \texttt{cooking\_lvl} (int): range from $1$ to $5$, - \item \texttt{cooking\_time} (int): in minutes (no negative numbers), - \item \texttt{ingredients} (list): list of all ingredients each represented by a string, - \item \texttt{description} (str): description of the recipe, - \item \texttt{recipe\_type} (str): can be "starter", "lunch" or "dessert". -\end{itemize} - -You have to \textbf{initialize} the object \texttt{Recipe} and check all its values, only the description can be empty. -In case of input errors, you should print what they are and exit properly. - -You will have to implement the built-in method \texttt{\_\_str\_\_}. -It's the method called when the following code is executed: - -\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} -tourte = Recipe(...) -to_print = str(tourte) -print(to_print) -\end{minted} - -It is implemented this way: - -\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} -def __str__(self): - """Return the string to print with the recipe info""" - txt = "" - """Your code here""" - return txt -\end{minted} - -The \texttt{Book} class also has some attributes: -\begin{itemize} - \item \texttt{name} (str): name of the book, - \item \texttt{last\_update} \href{https://docs.python.org/3/library/datetime.html}{(datetime)}: the date of the last update, - \item \texttt{creation\_date} \href{https://docs.python.org/3/library/datetime.html}{(datetime)}: the creation date, - \item \texttt{recipes\_list} (dict): a dictionnary with 3 keys: "starter", "lunch", "dessert". -\end{itemize} - - -You will have to implement some methods in \texttt{Book} class: - -\begin{minted}[bgcolor=darcula-back ,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} -def get_recipe_by_name(self, name): - """Prints a recipe with the name \texttt{name} and returns the instance""" - #... Your code here ... - -def get_recipes_by_types(self, recipe_type): - """Get all recipe names for a given recipe_type """ - #... Your code here ... - -def add_recipe(self, recipe): - """Add a recipe to the book and update last_update""" - #... Your code here ... -\end{minted} - -You have to handle the error if the argument passed in \texttt{add\_recipe} is not a \texttt{Recipe}. - - -Finally, you will provide a \texttt{test.py} file to test your classes and prove that they are working properly. -You can import all the classes into your \texttt{test.py} file by adding these lines at the top of the \texttt{test.py} file: - -\begin{minted}[bgcolor=darcula-back ,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} -from book import Book -from recipe import Recipe - -# ... Your tests ... -\end{minted} - +\input{exercises/m01ex00.tex} % ===========================(fin ex 00) % -% ============================================== % \newpage - -% ============================================== % % ===========================(start ex 01) % -\chapter{Exercise 01} -\extitle{Family tree} -\turnindir{ex01} -\exnumber{01} -\exfiles{game.py} -\exforbidden{None} -\makeheaderfilesforbidden - - -% ================================= % -\section*{Objective} -% --------------------------------- % -The goal of the exercise is to tackle the notion inheritance of class. - -% ================================= % -\section*{Instructions} -% --------------------------------- % -Create a \texttt{GotCharacter} class and initialize it with the following attributes: -\begin{itemize} - \item \texttt{first\_name}, - \item \texttt{is\_alive} (by default is \texttt{True}). -\end{itemize} - - -Pick up a GoT House (e.g., Stark, Lannister...) and create a child class that inherits from \texttt{GotCharacter} and -define the following attributes: -\begin{itemize} - \item \texttt{family\_name} (by default should be the same as the Class) - \item \texttt{house\_words} (e.g., the House words for the Stark House is: "Winter is Coming") -\end{itemize} - -\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} - class Stark(GotCharacter): - def __init__(self, first_name=None, is_alive=True): - super().__init__(first_name=first_name, is_alive=is_alive) - self.family_name = "Stark" - self.house_words = "Winter is Coming" -\end{minted} - -Add two methods to your child class: -\begin{itemize} - \item \texttt{print\_house\_words}: prints the House words, - \item \texttt{die}: changes the value of \texttt{is\_alive} to \texttt{False}. -\end{itemize} - -% ================================= % -\section*{Examples} -% --------------------------------- % - -Running commands in the Python console, an example of what you should get: -\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} - $> python - >>> from game import Stark - - >>> arya = Stark("Arya") - >>> print(arya.__dict__) - {'first_name': 'Arya', 'is_alive': True, 'family_name': 'Stark', 'house_words': 'Winter is Coming'} - - >>> arya.print_house_words() - Winter is Coming - - >>> print(arya.is_alive) - True - - >>> arya.die() - >>> print(arya.is_alive) - False -\end{minted} - -You can add any attribute or method you need to your class and format the docstring the way you want to. -Feel free to create other children of \texttt{GotCharacter} class. - -\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} - $> python - >>> from game import Stark - - >>> arya = Stark("Arya") - >>> print(arya.__doc__) - A class representing the Stark family. Or when bad things happen to good people. -\end{minted} - - +\input{exercises/m01ex01.tex} % ===========================(fin ex 01) % -% ============================================== % - \newpage - -% ============================================== % % ===========================(start ex 02) % -\chapter{Exercise 02} -\extitle{The Vector} -\turnindir{ex02} -\exnumber{02} -\exfiles{vector.py, test.py} -\exforbidden{Numpy library} -\makeheaderfilesforbidden - -% ================================= % -\section*{Objective} -% --------------------------------- % -The goal of the exercise is to get you used with built-in methods, more -particularly with those allowing to perform operations. -Student is expected to code built-in methods for vector-vector and -vector-scalar operations as rigorously as possible. - -% ================================= % -\section*{Instructions} -% --------------------------------- % -In this exercise, you have to create a \texttt{Vector} class. The goal is to -create vectors and be able to perform mathematical operations with them. -\begin{itemize} - \item Column vectors are represented as list of lists of single float (\texttt{[[1.], [2.], [3.]]}), - \item Row vectors are represented as a list of a list of several floats (\texttt{[[1., 2., 3.]]}). -\end{itemize} - -\warn{A vector is either a single line of floats or a single column of floats. When more than a line/column is consider, it is a matrix, not a vector.} - - -The class should also has 2 attributes: -\begin{itemize} - \item \texttt{values}: list of list of floats (for row vector) or list of lists of single float (for column vector), - \item \texttt{shape}: tuple of 2 integers: \texttt{(1,n)} for a row vector of dimension $n$ - or \texttt{(n,1)} for a column vector of dimension $n$. -\end{itemize} - -\info{If you did not learn at school what is the dimension of a vector, don't worry. -But for now do not think too hard about what dimension means. -Just consider the dimension is the number of floats (elements/coordinates) of a vector, and shape gives the layout: - if $(1, n)$ the vector is a row, if $(n,1)$ the vector is a column.} - -Finally you have to implement 2 methods: -\begin{itemize} - \item \texttt{.dot()} produce a dot product between two vectors of same \textbf{shape}, - \item \texttt{.T()} returns the transpose vector (i.e. a column vector into a row vector, or a row vector into a column vector). -\end{itemize} - -You will also provide a testing file (\texttt{test.py}) to demonstrate your class -works as expected. In this testing file, demonstrate: -\begin{itemize} - \item the addition and substraction are working for 2 vectors of the same shape, - \item the mutliplication (\texttt{mul} and \texttt{rmul}) are working for a vector and a scalar, - \item the division (\texttt{truediv}) is working with a vector and a scalar, - \item the division (\texttt{rtruediv}) raises an Arithmetic Error (this test can be commented for the other tests and uncommented to show this one), -\end{itemize} - -% ================================= % -\section*{Examples} -% --------------------------------- % -\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} -# Column vector of shape n * 1 -v1 = Vector([[0.0], [1.0], [2.0], [3.0]]) -v2 = v1 * 5 -print(v2) -# Expected output: -# Vector([[0.0], [5.0], [10.0], [15.0]]) - -# Row vector of shape 1 * n -v1 = Vector([[0.0, 1.0, 2.0, 3.0]]) -v2 = v1 * 5 -print(v2) -# Expected output -# Vector([[0.0, 5.0, 10.0, 15.0]]) - -v2 = v1 / 2.0 -print(v2) -# Expected output -# Vector([[0.0], [0.5], [1.0], [1.5]]) - -v1 / 0.0 -# Expected ouput -# ZeroDivisionError: division by zero. - -2.0 / v1 -# Expected output: -# NotImplementedError: Division of a scalar by a Vector is not defined here. -\end{minted} - - -\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} -# Column vector of shape (n, 1) -print(Vector([[0.0], [1.0], [2.0], [3.0]]).shape) -# Expected output -# (4,1) - -print(Vector([[0.0], [1.0], [2.0], [3.0]]).values) -# Expected output -# [[0.0], [1.0], [2.0], [3.0]] - -# Row vector of shape (1, n) -print(Vector([[0.0, 1.0, 2.0, 3.0]]).shape) -# Expected output -# (1,4) - -print(Vector([[0.0, 1.0, 2.0, 3.0]]).values) -# Expected output -# [[0.0, 1.0, 2.0, 3.0]] -\end{minted} - - -\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} -# Example 1: -v1 = Vector([[0.0], [1.0], [2.0], [3.0]]) -print(v1.shape) -# Expected output: -(4,1) - -print(v1.T()) -# Expected output: -# Vector([[0.0, 1.0, 2.0, 3.0]]) - -print(v1.T().shape) -# Expected output: -# (1,4) - -# Example 2: -v2 = Vector([[0.0, 1.0, 2.0, 3.0]]) -print(v2.shape) -# Expected output: -# (1,4) - -print(v2.T()) -# Expected output: -# Vector([[0.0], [1.0], [2.0], [3.0]]) - -print(v2.T().shape) -# Expected output: -# (4,1) -\end{minted} - -\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} - # Example 1: - v1 = Vector([[0.0], [1.0], [2.0], [3.0]]) - v2 = Vector([[2.0], [1.5], [2.25], [4.0]]) - print(v1.dot(v2)) - # Expected output: - # 18.0 - - v3 = Vector([[1.0, 3.0]]) - v4 = Vector([[2.0, 4.0]]) - print(v3.dot(v4)) - # Expected output: - # 13.0 - - v1 - # Expected output: to see what __repr__() should do - # [[0.0, 1.0, 2.0, 3.0]] - - print(v1) - # Expected output: to see what __str__() should do - # [[0.0, 1.0, 2.0, 3.0]] -\end{minted} - -You should be able to initialize the object with: -\begin{itemize} - \item a list of a list of floats: \texttt{Vector([[0.0, 1.0, 2.0, 3.0]])}, - \item a list of lists of single float: \texttt{Vector([[0.0], [1.0], [2.0], [3.0]])}, - \item a size: \texttt{Vector(3)} -> the vector will have \texttt{values = [[0.0], [1.0], [2.0]]}, - \item a range: \texttt{Vector((10,16))} -> the vector will have \texttt{values = [[10.0], [11.0], [12.0], [13.0], [14.0], [15.0]]}. -\end{itemize} - -\textit{By default, the vectors are generated as classical column vectors if initialized with a size or range.} - -To perform arithmetic operations for Vector-Vector or scalar-Vector, you have to implement all the following built-in functions (called \texttt{magic/special methods}) for your \texttt{Vector} class: - -\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} - __add__ - __radd__ - # add & radd : only vectors of same shape. - __sub__ - __rsub__ - # sub & rsub: only vectors of same shape. - __truediv__ - # truediv : only with scalars (to perform division of Vector by a scalar). - __rtruediv__ - # rtruediv : raises an NotImplementedError with the message "Division of a scalar by a Vector is not defined here." - __mul__ - __rmul__ - # mul & rmul: only scalars (to perform multiplication of Vector by a scalar). - __str__ - __repr__ - # must be identical, i.e we expect that print(vector) and vector within python interpretor behave the same, see corresponding example section. -\end{minted} - -\info{ - So it might be a good idea to implement \texttt{values} and \texttt{shape} before built-in arithmetic functions. - For the case not specify (e.g vector * vector) you should raise \texttt{NotImplementedError}. -} - - -% ================================= % -\section*{Mathematic notions} -% --------------------------------- % -The authorized vector operations are: - -\begin{itemize} - \item Addition between two vectors of same dimension $m$ - \begin{equation*} - x + y = - \begin{bmatrix} x_1 \\ \vdots \\ x_m\end{bmatrix} + - \begin{bmatrix} y_1 \\ \vdots \\ y_m\end{bmatrix} \\ - = \begin{bmatrix} x_1 + y_1 \\ \vdots \\ x_m + y_m \end{bmatrix} - \end{equation*} - \item Subtraction between two vectors of same dimension $m$ - \begin{equation*} - x - y = - \begin{bmatrix} x_1 \\ \vdots \\ y_m\end{bmatrix} - - \begin{bmatrix} x_1 \\ \vdots \\ y_m\end{bmatrix} - = \begin{bmatrix} x_1 - y_1 \\ \vdots \\ x_m - y_m \end{bmatrix} - \end{equation*} - \item Multiplication and division between one vector $m$ and one scalar. - \begin{equation*} - \alpha x = \alpha \begin{bmatrix} x_1 \\ \vdots \\ x_m\end{bmatrix} = - \begin{bmatrix} \alpha x_1 \\ \vdots \\ \alpha x_m \end{bmatrix} - \end{equation*} - \item Dot product between two vectors of same dimension $m$ - \begin{equation*} - x \cdot y = \begin{bmatrix} x_1 \\ \vdots \\ x_m\end{bmatrix} - \cdot - \begin{bmatrix} y_1 \\ \vdots \\ y_m\end{bmatrix} = - \sum_{i = 1}^{m} x_i \cdot y_i = x_1 \cdot y_1 + \dots + x_m \cdot y_m - \end{equation*} -\end{itemize} - -Do not forget to handle all types of error properly! - - +\input{exercises/m01ex02.tex} % ===========================(fin ex 02) % -% ============================================== % - \newpage - -% ============================================== % % ===========================(start ex 03) % -\chapter{Exercise 03} -\extitle{Generator!} -\turnindir{ex03} -\exnumber{03} -\exfiles{generator.py} -\exauthorize{random.randint} -\exforbidden{random.shuffle} -\makeheaderfilesforbidden - - -% ================================= % -\section*{Objective} -% --------------------------------- % -The goal of the exercise is to discover the concept of generator object in Python. - -% ================================= % -\section*{Instructions} -% --------------------------------- % -Code a function called \texttt{generator} that takes a text as input, uses the string -parameter \texttt{sep} as a splitting parameter, and \texttt{yield}s the resulting substrings. - -The function can take an optional argument. -The options are: -\begin{itemize} - \item \texttt{shuffle}: shuffles the list of words, - \item \texttt{unique}: returns a list where each word appears only once, - \item \texttt{ordered}: alphabetically sorts the words. -\end{itemize} - -\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} - # function prototype - def generator(text, sep=" ", option=None): - '''Splits the text according to sep value and yield the substrings. - option precise if a action is performed to the substrings before it is yielded. - ''' -\end{minted} - -You can only call one option at a time. - -% ================================= % -\section*{Examples} -% --------------------------------- % -\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} - >> text = "Le Lorem Ipsum est simplement du faux texte." - >> for word in generator(text, sep=" "): - ... print(word) - ... - Le - Lorem - Ipsum - est - simplement - du - faux - texte. - - >> for word in generator(text, sep=" ", option="shuffle"): - ... print(word) - ... - simplement - texte. - est - faux - Le - Lorem - Ipsum - du - - >> for word in generator(text, sep=" ", option="ordered"): - ... print(word) - ... - Ipsum - Le - Lorem - du - est - faux - simplement - texte. -\end{minted} - -\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} ->> text = "Lorem Ipsum Lorem Ipsum" ->> for word in generator(text, sep=" ", option="unique"): -... print(word) -... -Lorem -Ipsum -\end{minted} - -The function should return "ERROR" one time if the \texttt{text} argument is not a string, or if the \texttt{option} argument is not valid. - -\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} ->> text = 1.0 ->> for word in generator(text, sep="."): -... print(word) -... -ERROR -\end{minted} - - +\input{exercises/m01ex03.tex} % ===========================(fin ex 03) % -% ============================================== % - \newpage - -% ============================================== % % ===========================(start ex 04) % -\chapter{Exercise 04} -\extitle{Working with lists} -\turnindir{ex04} -\exnumber{04} -\exfiles{eval.py} -\exauthorize{zip and enumerate} -\exforbidden{while} -\makeheaderfilesforbidden - - -% ================================= % -\section*{Objective} -% --------------------------------- % -The goal of the exercise is to discover 2 useful methods for lists, tuples, -dictionnaries (iterable class objects more generally) named \texttt{zip} -and \texttt{enumerate}. - -% ================================= % -\section*{Instructions} -% --------------------------------- % -Code a class \texttt{Evaluator}, that has two static functions named \texttt{zip\_evaluate} -and \texttt{enumerate\_evaluate}. - - -The goal of these 2 functions is to compute the sum of the lengths of every -\texttt{words} of a given list weighted by a list of coefficinents \texttt{coefs} (yes, the 2 functions should do the same thing). - -The lists \texttt{coefs} and \texttt{words} have to be the same length. If this is not the -case, the function should return -1. - -You have to obtain the desired result using \texttt{zip} in the \texttt{zip\_evaluate} function, -and with \texttt{enumerate} in the \texttt{enumerate\_evaluate} function. - -% ================================= % -\section*{Examples} -% --------------------------------- % -\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} ->> from eval import Evaluator ->> ->> words = ["Le", "Lorem", "Ipsum", "est", "simple"] ->> coefs = [1.0, 2.0, 1.0, 4.0, 0.5] ->> Evaluator.zip_evaluate(coefs, words) -32.0 ->> words = ["Le", "Lorem", "Ipsum", "n'", "est", "pas", "simple"] ->> coefs = [0.0, -1.0, 1.0, -12.0, 0.0, 42.42] ->> Evaluator.enumerate_evaluate(coefs, words) --1 -\end{minted} - - +\input{exercises/m01ex04.tex} % ===========================(fin ex 04) % -% ============================================== % - \newpage - -% ============================================== % % ===========================(start ex 05) % -\chapter{Exercise 05} -\extitle{Bank Account} -\turnindir{ex05} -\exnumber{05} -\exfiles{the\_bank.py} -\exforbidden{None} -\makeheaderfilesforbidden - -% ================================= % -\section*{Objective} -% --------------------------------- % -The goals of this exercise is to discover new built-in functions and -deepen your class manipulation and to be aware of possibility -to modify instanced objects.\\ -In this exercise you learn how to modify or add attributes to an object. - -% ================================= % -\section*{Instructions} -% --------------------------------- % -It is all about security. -Have a look at the class named \texttt{Account} in the snippet of code below. - -\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} -# in the_bank.py -class Account(object): - - ID_COUNT = 1 - - def __init__(self, name, **kwargs): - self.__dict__.update(kwargs) - - self.id = self.ID_COUNT - Account.ID_COUNT += 1 - self.name = name - if not hasattr(self, 'value'): - self.value = 0 - - if self.value < 0: - raise AttributeError("Attribute value cannot be negative.") - if not isinstance(self.name, str) - raise AttributeError("Attribute name must be a str object.") - - def transfer(self, amount): - self.value += amount -\end{minted} - -Now, it is your turn to code a class named \texttt{Bank}! -Its purpose will be to handle the security part of each transfer attempt. - -Security means checking if the \texttt{Account} is: -\begin{itemize} - \item the right object, - \item not corrupted, - \item and stores enough money to complete the transfer. -\end{itemize} - -How do we define if a bank account is corrupted? A corrupted bank account has: -\begin{itemize} - \item an even number of attributes, - \item an attribute starting with \texttt{b}, - \item no attribute starting with \texttt{zip} or \texttt{addr}, - \item no attribute \texttt{name}, \texttt{id} and \texttt{value}, - \item \texttt{name} not being a string, - \item \texttt{id} not being an \texttt{int}, - \item \texttt{value} not being an \texttt{int} or a \texttt{float}. -\end{itemize} - -For the rest of the attributes (\texttt{addr}, \texttt{zip}, etc ... -there is no specific check expected. -Meaning you are not expected to evaluate the validity of the account based on the type of the other attributes (the conditions listed above are sufficient). - -Moreover, verification has to be performed when account objects are added to to Bank instance -(\texttt{bank.add(Account(...))}). -The verification in \texttt{add} only check the type of the new\_account and if there -is no account among the one already in Bank instance with the same name. - -A transaction is invalid if \texttt{amount < 0} or if the amount is larger than -the balance of the account. -Prior to the transfer, the validity of the 2 accounts (\texttt{origin} and \texttt{dest}) are checked -(according to the list of criteria above). -A transfer between the same account (\texttt{bank.transfer('Wiliam John', 'William John')}) -is valid but there is no fund movement. - -\texttt{fix\_account} recovers a corrupted account if it parameter \texttt{name} correspond to the attribute -name of one of the account in \texttt{accounts} (attribute of Bank). If name is not a string or does not corresponded -to an account name, the method return \texttt{False}. - -\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} -# in the_bank.py -class Bank(object): - """The bank""" - def __init__(self): - self.accounts = [] - - def add(self, new_account): - """ Add new_account in the Bank - @new_account: Account() new account to append - @return True if success, False if an error occured - """ - # test if new_account is an Account() instance and if - # it can be appended to the attribute accounts - - # ... Your code ... - - self.accounts.append(new_account) - - def transfer(self, origin, dest, amount): - """" Perform the fund transfer - @origin: str(name) of the first account - @dest: str(name) of the destination account - @amount: float(amount) amount to transfer - @return True if success, False if an error occured - """ - # ... Your code ... - - def fix_account(self, name): - """ fix account associated to name if corrupted - @name: str(name) of the account - @return True if success, False if an error occured - """ - # ... Your code ... -\end{minted} - -Check out the \texttt{dir} built-in function. - -\warn{YOU WILL HAVE TO MODIFY THE INSTANCES' ATTRIBUTES IN ORDER TO FIX THEM.} - -% ================================= % -\section*{Examples} -% --------------------------------- % -The script \texttt{banking\_test1.py} is a test which must print \texttt{Failed}. -The second script \texttt{banking\_test2.py} is a test which must print \texttt{Failed} and then \texttt{Success}. - -\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{bash} ->> python banking_test1.py -Failed -# The transaction is not performed has the account of Smith Jane is corrupted (due to the attribute 'bref'). - ->> python banking_test2.py -Failed -Success -# the account are false due to the abscence of addr attribute, fix_account recover the account, -# thus they become valid. -\end{minted} - - +\input{exercises/m01ex05.tex} % ===========================(fin ex 05) % -% ============================================== % - \newpage - -% ================================= % -\section*{Contact} -% --------------------------------- % -You can contact 42AI association by email: contact@42ai.fr\\ -You can join the association on \href{https://join.slack.com/t/42-ai/shared_invite/zt-ebccw5r7-YPkDM6xOiYRPjqJXkrKgcA}{42AI slack} -and/or posutale to \href{https://forms.gle/VAFuREWaLmaqZw2D8}{one of the association teams}. - -% ================================= % -\section*{Acknowledgements} -% --------------------------------- % -The modules Python \& ML is the result of a collective work, we would like to thanks: -\begin{itemize} - \item Maxime Choulika (cmaxime), - \item Pierre Peigné (ppeigne), - \item Matthieu David (mdavid). -\end{itemize} -who supervised the creation, the enhancement and this present transcription. - -\begin{itemize} - \item Amric Trudel (amric@42ai.fr) - \item Baptiste Lefeuvre (blefeuvr@student.42.fr) - \item Mathilde Boivin (mboivin@student.42.fr) - \item Tristan Duquesne (tduquesn@student.42.fr) - \item Quentin Feuillade Montixi (qfeuilla@student.42.fr) -\end{itemize} -for your investment for the creation and development of these modules. - -\begin{itemize} - \item Barthélémy Leveque (bleveque@student.42.fr) - \item Remy Oster (roster@student.42.fr) - \item Quentin Bragard (qbragard@student.42.fr) - \item Marie Dufourq (madufour@student.42.fr) - \item Adrien Vardon (advardon@student.42.fr) -\end{itemize} -who betatest the first version of the modules of Machine Learning. -\vfill -\doclicenseThis +\input{en.acknowledgements.tex} \end{document} \ No newline at end of file diff --git a/module02/subject/assets/42ai_logo.pdf b/module02/subject/assets/42ai_logo.pdf index c915fc5c..1f5d3abb 100644 Binary files a/module02/subject/assets/42ai_logo.pdf and b/module02/subject/assets/42ai_logo.pdf differ diff --git a/module02/subject/en.acknowledgements.tex b/module02/subject/en.acknowledgements.tex new file mode 100644 index 00000000..fb0f07cb --- /dev/null +++ b/module02/subject/en.acknowledgements.tex @@ -0,0 +1,38 @@ +\section*{Contact} +% --------------------------------- % +You can contact 42AI by email: \href{mailto:contact@42ai.fr}{contact@42ai.fr}\\ +\newline +Thank you for attending 42AI's Python Bootcamp module02 ! + +% ================================= % +\section*{Acknowledgements} +% --------------------------------- % +The Python bootcamp is the result of a collective work, for which we would like to thank: +\begin{itemize} + \item Maxime Choulika (cmaxime), + \item Pierre Peigné (ppeigne, pierre@42ai.fr), + \item Matthieu David (mdavid, matthieu@42ai.fr), + \item Quentin Feuillade--Montixi (qfeuilla, quentin@42ai.fr) + \item Mathieu Perez (maperez, mathieu.perez@42ai.fr) +\end{itemize} +who supervised the creation, the enhancement of the bootcamp and this present transcription. + +\begin{itemize} + \item Louis Develle (ldevelle, louis@42ai.fr) + \item Augustin Lopez (aulopez) + \item Luc Lenotre (llenotre) + \item Owen Roberts (oroberts) + \item Thomas Flahault (thflahau) + \item Amric Trudel (amric@42ai.fr) + \item Baptiste Lefeuvre (blefeuvr@student.42.fr) + \item Mathilde Boivin (mboivin@student.42.fr) + \item Tristan Duquesne (tduquesn@student.42.fr) +\end{itemize} +for your investment in the creation and development of these modules. + +\begin{itemize} + \item All prior participants who took a moment to provide their feedbacks, and help us improve these bootcamps ! +\end{itemize} + + \vfill +\doclicenseThis \ No newline at end of file diff --git a/module02/subject/en.instructions.tex b/module02/subject/en.instructions.tex new file mode 100644 index 00000000..4baebb69 --- /dev/null +++ b/module02/subject/en.instructions.tex @@ -0,0 +1,36 @@ +\chapter{Common Instructions} +\begin{itemize} + \item The version of Python recommended to use is 3.7, you can + check the version of Python with the following command: \texttt{python -V} + + \item The norm: during this bootcamp, it is recommended to follow the + \href{https://www.python.org/dev/peps/pep-0008/}{PEP 8 standards}, though it is not mandatory. + You can install \href{https://pypi.org/project/pycodestyle}{pycodestyle} which + is a tool to check your Python code. + \item The function \texttt{eval} is never allowed. + \item The exercises are ordered from the easiest to the hardest. + \item Your exercises are going to be evaluated by someone else, + so make sure that your variable names and function names are appropriate and civil. + \item Your manual is the internet. + + \item If you are a student from 42, you can access our Discord server + on \href{https://discord.com/channels/887850395697807362/887850396314398720}{42 student's associations portal} and ask your + questions to your peers in the dedicated Bootcamp channel. + + \item You can learn more about 42 Artificial Intelligence by visiting \href{https://42-ai.github.io}{our website}. + + \item If you find any issue or mistake in the subject please create an issue on \href{https://github.com/42-AI/bootcamp_python/issues}{42AI repository on Github}. + + \item We encourage you to create test programs for your + project even though this work \textbf{won't have to be + submitted and won't be graded}. It will give you a chance + to easily test your work and your peers’ work. You will find + those tests especially useful during your defence. Indeed, + during defence, you are free to use your tests and/or the + tests of the peer you are evaluating. + + \item We are constantly looking to improve these bootcamps, and your feedbacks are essential for us to do so !\\ + You can tell us more about your experience with this module by filling \href{https://forms.gle/xbm2VjynZq8BfpbM6}{this form}.\\ + Thank you in advance and good luck for this bootcamp ! + +\end{itemize} \ No newline at end of file diff --git a/module02/subject/en.py_proj.tex b/module02/subject/en.py_proj.tex deleted file mode 100644 index 95cf19ca..00000000 --- a/module02/subject/en.py_proj.tex +++ /dev/null @@ -1,45 +0,0 @@ -%******************************************************************************% -% % -% Common Instructions % -% for Python Projects % -% % -%******************************************************************************% - -\chapter{Common Instructions} -\begin{itemize} - \item The version of Python recommended to use is 3.7, you can - check the version of Python with the following command: \texttt{python -V} - - \item The norm: during this bootcamp you will follow the - \href{https://www.python.org/dev/peps/pep-0008/}{PEP 8 standards}. - You can install \href{https://pypi.org/project/pycodestyle}{pycodestyle} which - is a tool to check your Python code. - - \item The function \texttt{eval} is never allowed. - - \item The exercises are ordered from the easiest to the hardest. - - \item Your exercises are going to be evaluated by someone else, - so make sure that your variable names and function names are appropriate and civil. - - \item Your manual is the internet. - - \item You can also ask questions in the \texttt{\#bootcamps} channel in the \href{https://42-ai.slack.com}{42AI} - or \href{42born2code.slack.com}{42born2code}. - - \item If you find any issue or mistakes in the subject please create an issue on \href{https://github.com/42-AI/bootcamp_python/issues}{42AI repository on Github}. - - \item We encourage you to create test programs for your - project even though this work \textbf{won't have to be - submitted and won't be graded}. It will give you a chance - to easily test your work and your peers’ work. You will find - those tests especially useful during your defence. Indeed, - during defence, you are free to use your tests and/or the - tests of the peer you are evaluating. - - \item Submit your work to your assigned git repository. Only the work in the - git repository will be graded. If Deepthought is assigned to grade your - work, it will be run after your peer-evaluations. - If an error happens in any section of your work during Deepthought's grading, - the evaluation will stop. -\end{itemize} \ No newline at end of file diff --git a/module02/subject/en.subject.pdf b/module02/subject/en.subject.pdf new file mode 100644 index 00000000..a4721434 Binary files /dev/null and b/module02/subject/en.subject.pdf differ diff --git a/module02/subject/en.subject.pdf.version b/module02/subject/en.subject.pdf.version deleted file mode 100644 index 56a6051c..00000000 --- a/module02/subject/en.subject.pdf.version +++ /dev/null @@ -1 +0,0 @@ -1 \ No newline at end of file diff --git a/module02/subject/en.subject.tex b/module02/subject/en.subject.tex index 3150c986..9ebad2d6 100644 --- a/module02/subject/en.subject.tex +++ b/module02/subject/en.subject.tex @@ -118,7 +118,7 @@ % =============================================================================% % ===================================== % -\title{Python \& ML - Module 02} +\title{Python Bootcamp - Module 02} \subtitle{Basics 3} \author{ Maxime Choulika (cmaxime), Pierre Peigné (ppeigne), Matthieu David (mdavid) @@ -127,11 +127,11 @@ \summary { Let's continue practicing with more advanced Python programming exercises. - Destination: Decorators, lambda, context manager and build package. + Destination: Decorators, lambda, context manager and packaging. } \maketitle -\input{en.py_proj.tex} +\input{en.instructions.tex} \newpage \tableofcontents \startexercices @@ -148,654 +148,41 @@ % ============================================== % % ===========================(start ex 00) % -\chapter{Exercise 00} -\extitle{Map, filter, reduce} -\turnindir{ex00} -\exnumber{00} -\exfiles{ft\_map.py, ft\_filter.py, ft\_reduce.py} -\exforbidden{map, filter, reduce} -\makeheaderfilesforbidden - -% ================================== % -\section*{Objective} -% ---------------------------------- % -The goal of the exercise is to work on the built-in functions \texttt{map}, -\texttt{filter} and \texttt{reduce}. - -% ================================== % -\section*{Instructions} -% ---------------------------------- % -Implement the functions \texttt{ft\_map}, \texttt{ft\_filter} and \texttt{ft\_reduce}. -Take the time to understand the use cases of these two built-in functions -(\texttt{map} and \texttt{filter}) and the function \texttt{reduce} in functools module. -You are not expected to code specific classes to create \texttt{ft\_map}, -\texttt{ft\_filter} or \texttt{ft\_reduce} objects, take a closer look -to the examples to know what to do. - -Here the signatures of the functions: - -\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} -def ft_map(function_to_apply, iterable): - """Map the function to all elements of the iterable. - Args: - function_to_apply: a function taking an iterable. - iterable: an iterable object (list, tuple, iterator). - Return: - An iterable. - None if the iterable can not be used by the function. - """ - # ... Your code here ... - -def ft_filter(function_to_apply, iterable): - """Filter the result of function apply to all elements of the iterable. - Args: - function_to_apply: a function taking an iterable. - iterable: an iterable object (list, tuple, iterator). - Return: - An iterable. - None if the iterable can not be used by the function. - """ - # ... Your code here ... - -def ft_reduce(function_to_apply, iterable): - """Apply function of two arguments cumulatively. - Args: - function_to_apply: a function taking an iterable. - iterable: an iterable object (list, tuple, iterator). - Return: - A value, of same type of elements in the iterable parameter. - None if the iterable can not be used by the function. - """ - # ... Your code here ... -\end{minted} - -% ================================== % -\section*{Examples} -% ---------------------------------- % - -\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} -# Example 1: -x = [1, 2, 3, 4, 5] -ft_map(lambda dum: dum + 1, x) -# Output: - # The adress will be different - -list(ft_map(lambda t: t + 1, x)) -# Output: -[2, 3, 4, 5, 6] - -# Example 2: -ft_filter(lambda dum: not (dum % 2), x) -# Output: - # The adress will be different - -list(ft_filter(lambda dum: not (dum % 2), x)) -# Output: -[2, 4] - -# Example 3: -lst = ['H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd'] -ft_reduce(lambda u, v: u + v, lst) -# Output: -"Hello world" -\end{minted} - -You are expected to produce the raise of exception for the functions similar to exceptions of -\texttt{map}, \texttt{filter} and \texttt{reduce} when wrong parameters are given (but no need -to reproduce the exact the same exception messages). - +\input{exercises/m02ex00.tex} % ===========================(fin ex 00) % % ============================================== % \newpage - % ============================================== % % ===========================(start ex 01) % -\chapter{Exercise 01} -\extitle{args and kwargs?} -\turnindir{ex01} -\exnumber{01} -\exfiles{main.py} -\exforbidden{None} -\makeheaderfilesforbidden - -% ================================= % -\section*{Objective} -% --------------------------------- % -The goal of the exercise is to discover and manipulate \texttt{*args} and \texttt{**kwargs} arguments. - -% ================================= % -\section*{Instructions} -% --------------------------------- % -In this exercise you have to implement a function named \texttt{what\_are\_the\_vars} -which returns an instance of class ObjectC.\\ -ObjectC attributes are set via the parameters received during the instanciation. -You will have to modify the 'instance' \texttt{ObjectC}, \textbf{NOT} the class.\\ -You should take a look to \texttt{getattr}, \texttt{setattr} built-in functions. - -\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} -def what_are_the_vars(...): - """ - ... - """ - # ... Your code here ... - -class ObjectC(object): - def __init__(self): - # ... Your code here ... - -def doom_printer(obj): - if obj is None: - print("ERROR") - print("end") - return - for attr in dir(obj): - if attr[0] != '_': - value = getattr(obj, attr) - print("{}: {}".format(attr, value)) - print("end") - -if __name__ == "__main__": - obj = what_are_the_vars(7) - doom_printer(obj) - obj = what_are_the_vars(None, []) - doom_printer(obj) - obj = what_are_the_vars("ft_lol", "Hi") - doom_printer(obj) - obj = what_are_the_vars() - doom_printer(obj) - obj = what_are_the_vars(12, "Yes", [0, 0, 0], a=10, hello="world") - doom_printer(obj) - obj = what_are_the_vars(42, a=10, var_0="world") - doom_printer(obj) - obj = what_are_the_vars(42, "Yes", a=10, var_2="world") - doom_printer(obj) -\end{minted} - -% ================================= % -\section*{Examples} -% --------------------------------- % - -\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} -$> python main.py -var_0: 7 -end -var_0: None -var_1: [] -end -var_0: ft_lol -var_1: Hi -end -end -a: 10 -hello: world -var_0: 12 -var_1: Yes -var_2: [0, 0, 0] -end -ERROR -end -a: 10 -var_0: 12 -var_1: Yes -var_2: world -end -\end{minted} - +\input{exercises/m02ex01.tex} % ===========================(fin ex 01) % % ============================================== % - \newpage - % ============================================== % % ===========================(start ex 02) % -\chapter{Exercise 02} -\extitle{The logger} -\turnindir{ex02} -\exnumber{02} -\exfiles{logger.py} -\exforbidden{None} -\makeheaderfilesforbidden - -% ================================= % -\section*{Objective} -% --------------------------------- % -In this exercise, you will learn about decorators and we are not talking about -the decoration of your room. -The \texttt{@log} will write info about the decorated function in a -\texttt{machine.log} file. - -% ================================= % -\section*{Instructions} -% --------------------------------- % -You have to create the log decorator in the same file. -Pay attention to all the different actions logged at the call of -each methods. You may notice the username from environment -variable is written to the log file. - - -\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} -import time -from random import randint -import os - -#... your definition of log decorator... - -class CoffeeMachine(): - - water_level = 100 - - @log - def start_machine(self): - if self.water_level > 20: - return True - else: - print("Please add water!") - return False - - @log - def boil_water(self): - return "boiling..." - - @log - def make_coffee(self): - if self.start_machine(): - for _ in range(20): - time.sleep(0.1) - self.water_level -= 1 - print(self.boil_water()) - print("Coffee is ready!") - - @log - def add_water(self, water_level): - time.sleep(randint(1, 5)) - self.water_level += water_level - print("Blub blub blub...") - - -if __name__ == "__main__": - - machine = CoffeeMachine() - for i in range(0, 5): - machine.make_coffee() - - machine.make_coffee() - machine.add_water(70) -\end{minted} - -% ================================= % -\section*{Examples} -% --------------------------------- % -\begin{42console} - $> python logger.py - boiling... - Coffee is ready! - boiling... - Coffee is ready! - boiling... - Coffee is ready! - boiling... - Coffee is ready! - Please add water! - Please add water! - Blub blub blub... - $> -\end{42console} - -\begin{42console} - $> cat machine.log - (cmaxime)Running: Start Machine [ exec-time = 0.001 ms ] - (cmaxime)Running: Boil Water [ exec-time = 0.005 ms ] - (cmaxime)Running: Make Coffee [ exec-time = 2.499 s ] - (cmaxime)Running: Start Machine [ exec-time = 0.002 ms ] - (cmaxime)Running: Boil Water [ exec-time = 0.005 ms ] - (cmaxime)Running: Make Coffee [ exec-time = 2.618 s ] - (cmaxime)Running: Start Machine [ exec-time = 0.003 ms ] - (cmaxime)Running: Boil Water [ exec-time = 0.004 ms ] - (cmaxime)Running: Make Coffee [ exec-time = 2.676 s ] - (cmaxime)Running: Start Machine [ exec-time = 0.003 ms ] - (cmaxime)Running: Boil Water [ exec-time = 0.004 ms ] - (cmaxime)Running: Make Coffee [ exec-time = 2.648 s ] - (cmaxime)Running: Start Machine [ exec-time = 0.011 ms ] - (cmaxime)Running: Make Coffee [ exec-time = 0.029 ms ] - (cmaxime)Running: Start Machine [ exec-time = 0.009 ms ] - (cmaxime)Running: Make Coffee [ exec-time = 0.024 ms ] - (cmaxime)Running: Add Water [ exec-time = 5.026 s ] - $> -\end{42console} - -Pay attention, the length between ":" and "[" is 20]. -Draw the corresponding conclusions on this part of a log entry. - +\input{exercises/m02ex02.tex} % ===========================(fin ex 02) % % ============================================== % - \newpage - % ============================================== % % ===========================(start ex 03) % -\chapter{Exercise 03} -\extitle{Json issues} -\turnindir{ex03} -\exnumber{03} -\exfiles{csvreader.py} -\exforbidden{None} -\makeheaderfilesforbidden - -% ================================= % -\section*{Objective} -% --------------------------------- % -The goal of this exercise is to implement a context manager as a class. -Thus you are strongly encouraged to do some research about context manager. - -% ================================= % -\section*{Instructions} -% --------------------------------- % -Implement a \texttt{CsvReader} class that opens, reads, and parses a CSV file. -This class is then a context manager as class. -In order to create it, your class requires a few built-in methods: -\begin{itemize} - \item \texttt{\_\_init\_\_}, - \item \texttt{\_\_enter\_\_}, - \item \texttt{\_\_exit\_\_}. -\end{itemize} -It is mandatory to close the file once the process has completed. -You are expected to handle properly badly formatted CSV file (i.e. handle the exception): -\begin{itemize} - \item mistmatch between number of fields and number of records, - \item records with different length. -\end{itemize} - -\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} - class CsvReader(): - def __init__(self, filename=None, sep=',', header=False, skip_top=0, skip_bottom=0): - # ... Your code here ... - - def __enter__(...): - # ... Your code here ... - - def __exit__(...): - # ... Your code here ... - - def getdata(self): - """ Retrieves the data/records from skip_top to skip bottom. - Return: - nested list (list(list, list, ...)) representing the data. - """ - # ... Your code here ... - - def getheader(self): - """ Retrieves the header from csv file. - Returns: - list: representing the data (when self.header is True). - None: (when self.header is False). - """ - # ... Your code here ... -\end{minted} - -\texttt{CSV} (for Comma-Separated Values) file is a delimited text file which uses a comma to separate values. -Therefore, the field separator (or delimiter) is usually a comma (\texttt{,}) -but with your context manager you have to offer the possibility to change this parameter. - - -One can decide if the class instance skips lines at the top and the bottom of the file via the -parameters \texttt{skip\_top} and \texttt{skip\_bottom}. -One should also be able to keep the first line as a header if \texttt{header} is \texttt{True}. - - -The file should not be corrupted (either a line with too many values or a line -with too few values), otherwise return \texttt{None}.\\ -You have to handle the case \texttt{file not found}.\\ - - -You are expected to implement two methods: -\begin{itemize} - \item \texttt{getdata()}, - \item \texttt{getheader()}. -\end{itemize} - -\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} -from csvreader import CsvReader - -if __name__ == "__main__": - with CsvReader('good.csv') as file: - data = file.getdata() - header = file.getheader() -\end{minted} - -\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} -from csvreader import CsvReader - -if __name__ == "__main__": - with CsvReader('bad.csv') as file: - if file == None: - print("File is corrupted") -\end{minted} - - +\input{exercises/m02ex03.tex} % ===========================(fin ex 03) % % ============================================== % - \newpage - % ============================================== % % ===========================(start ex 04) % -\chapter{Exercise 04} -\extitle{MiniPack} -\turnindir{ex04} -\exnumber{04} -\exfiles{build.sh, *.py, *.md, *.cfg, *.txt} -\exforbidden{None} -\makeheaderfilesforbidden - - -% ================================= % -\section*{Objective} -% --------------------------------- % -The goal of the exercise is to learn how to build a package and understand the magnificence of \href{https://pypi.org/}{PyPi}. - - -% ================================= % -\section*{Instructions} -% --------------------------------- % -You have to create a package called \texttt{my\_minipack}. -\hint{\href{https://docs.python.org/3.9/distributing/index.html}{RTFM}} - -It will have 2 \textbf{modules}: -\begin{itemize} - \item the progress bar (module00 ex10) which should be imported it via \texttt{import my\_minipack.progressbar}, - \item the logger (module02 ex02), which should be imported via \texttt{import my\_minipack.logger}. -\end{itemize} - - -The package will be installed via pip using one of the following commands (both should work): -\begin{42console} - $> pip install ./dist/my_minipack-1.0.0.tar.gz - $> pip install ./dist/my_minipack-1.0.0-py3-none-any.whl -\end{42console} - -Based on the following terminal commands and corresponding outputs, draw the necessary conclusion. - -\begin{42console} - $> python -m venv tmp_env && source tmp_env/bin/activate - (tmp_env) > pip list - # Ouput - Package Version - ---------- ------- - pip 19.0.3 - setuptools 40.8.0 - - (tmp_env) $> cd ex04/ && bash build.sh - # Output ... No specific verbose expected, do as you wish ... - ... - (tmp_env) $> ls dist - # Output - my_minipack-1.0.0-py3-none-any.whl my_minipack-1.0.0.tar.gz - - (tmp_env) $> pip list - # Output - Package Version - ----------- ------- - my-minipack 1.0.0 - pip 21.0.1 # the last version at the time - setuptools 54.2.0 # the last version at the time - wheel 0.36.2 # the last version at the time - - (tmp_env) $> pip show -v my_minipack - # Ouput (minimum metadata asked) - Name: my-minipack - Version: 1.0.0 - Summary: Howto create a package in python. - Home-page: None - Author: mdavid - Author-email: mdavid@student.42.fr - License: GPLv3 - Location: [PATH TO BOOTCAMP PYTHON]/module02/tmp_env/lib/python3.7/site-packages - Requires: - Required-by: - Metadata-Version: 2.1 - Installer: pip - Classifiers: - Development Status :: 3 - Alpha - Intended Audience :: Developers - Intended Audience :: Students - Topic :: Education - Topic :: HowTo - Topic :: Package - License :: OSI Approved :: GNU General Public License v3 (GPLv3) - Programming Language :: Python :: 3 - Programming Language :: Python :: 3 :: Only -(tmp_env) $> -\end{42console} - -The `build.sh` script upgrades `pip`, and \textbf{builds} the distribution packages in `wheel` and `egg` format. - -\info{ -You can ensure whether the package was properly installed by running the command \texttt{pip list} -that displays the list of installed packages and check the metadata of the package with -\texttt{pip show -v my\_minipack}. -Of course do not reproduce the exact same metadata, change the author information, modify the summary Topic and Audience items if you want to. -} +\input{exercises/m02ex04.tex} % ===========================(fin ex 04) % % ============================================== % \newpage - % ============================================== % % ===========================(start ex 05) % -\chapter{Exercise 05} -\extitle{TinyStatistician} -\turnindir{ex05} -\exnumber{05} -\exfiles{TinyStatistician.py} -\exforbidden{Any function that calculates mean, median, quartiles, variance or standar deviation for you.} -\makeheaderfilesforbidden - - -% ================================= % -\section*{Objective} -% --------------------------------- % -Initiation to very basic statistic notions. - -% ================================= % -\section*{Instructions} -% --------------------------------- % -Create a class named \texttt{TinyStatistician} that implements the following methods: -\begin{itemize} - \item \texttt{mean(x)}: computes the mean of a given non-empty list or array \texttt{x}, using a for-loop. - The method returns the mean as a float, otherwise \texttt{None} if \texttt{x} is an empty list or array. - Given a vector \texttt{x} of dimension $m \times 1$, the mathematical formula of its mean is: - $$ - \mu = \frac{\sum_{i = 1}^{m}{x_i}}{m} - $$ - \item \texttt{median(x)}: computes the median of a given non-empty list or array \texttt{x}. - The method returns the median as a float, otherwise \texttt{None} if \texttt{x} is an empty list or array. - \item \texttt{quartiles(x)}: computes the $1^{\text{st}}$ and $3^{\text{rd}}$ quartiles of a given non-empty array \texttt{x}. - The method returns the quartile as a float, otherwise \texttt{None} if \texttt{x} is an empty list or array. - \item \texttt{var(x)}: computes the variance of a given non-empty list or array \texttt{x}, using a for-loop. - The method returns the variance as a float, otherwise \texttt{None} if \texttt{x} is an empty list or array. - Given a vector \texttt{x} of dimension $m \times 1$, the mathematical formula of its variance is: - $$ - \sigma^2 = \frac{\sum_{i = 1}^{m}{(x_i - \mu)^2}}{m} = \frac{\sum_{i = 1}^{m}{[x_i - (\frac{1}{m}\sum_{j = 1}^{m}{x_j}})]^2}{m} - $$ - \item \texttt{std(x)} : computes the standard deviation of a given non-empty list or array \texttt{x}, using a for-loop. - The method returns the standard deviation as a float, otherwise \texttt{None} if \texttt{x} is an empty list or array. - Given a vector \texttt{x} of dimension $m \times 1$, the mathematical formula of its standard deviation is: - $$ - \sigma = \sqrt{\frac{\sum_{i = 1}^{m}{(x_i - \mu)^2}}{m}} = \sqrt{\frac{\sum_{i = 1}^{m}{[x_i - (\frac{1}{m}\sum_{j = 1}^{m}{x_j}})]^2}{m}} - $$ -\end{itemize} - -All methods take a \texttt{list} or a \texttt{numpy.ndarray} as parameter.\\ -We are assuming that all inputs have a correct format, i.e. a list or array of numeric type or empty list or array. -You don't have to protect your functions against input errors. - - -% ================================= % -\section*{Examples} -% --------------------------------- % -\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} -from TinyStatistician import TinyStatistician -tstat = TinyStatistician() -a = [1, 42, 300, 10, 59] - -tstat.mean(a) -# Expected result: 82.4 - -tstat.median(a) -# Expected result: 42.0 - -tstat.quartile(a) -# Expected result: [10.0, 59.0] - -tstat.var(a) -# Expected result: 12279.439999999999 - -tstat.std(a) -# Expected result: 110.81263465868862 -\end{minted} - - - +\input{exercises/m02ex05.tex} % ===========================(fin ex 05) % % ============================================== % - \newpage - % ================================= % -\section*{Contact} -% --------------------------------- % -You can contact 42AI association by email: contact@42ai.fr\\ -You can join the association on \href{https://join.slack.com/t/42-ai/shared_invite/zt-ebccw5r7-YPkDM6xOiYRPjqJXkrKgcA}{42AI slack} -and/or posutale to \href{https://forms.gle/VAFuREWaLmaqZw2D8}{one of the association teams}. - +\input{en.acknowledgements.tex} % ================================= % -\section*{Acknowledgements} -% --------------------------------- % -The modules Python \& ML is the result of a collective work, we would like to thanks: -\begin{itemize} - \item Maxime Choulika (cmaxime), - \item Pierre Peigné (ppeigne), - \item Matthieu David (mdavid). -\end{itemize} -who supervised the creation, the enhancement and this present transcription. - -\begin{itemize} - \item Amric Trudel (amric@42ai.fr) - \item Baptiste Lefeuvre (blefeuvr@student.42.fr) - \item Mathilde Boivin (mboivin@student.42.fr) - \item Tristan Duquesne (tduquesn@student.42.fr) - \item Quentin Feuillade Montixi (qfeuilla@student.42.fr) -\end{itemize} -for your investment for the creation and development of these modules. - -\begin{itemize} - \item Barthélémy Leveque (bleveque@student.42.fr) - \item Remy Oster (roster@student.42.fr) - \item Quentin Bragard (qbragard@student.42.fr) - \item Marie Dufourq (madufour@student.42.fr) - \item Adrien Vardon (advardon@student.42.fr) -\end{itemize} -who betatest the first version of the modules of Machine Learning. -\vfill -\doclicenseThis - -\end{document} \ No newline at end of file +\end{document} diff --git a/module02/subject/exercises/m02ex00.tex b/module02/subject/exercises/m02ex00.tex new file mode 100644 index 00000000..bea8f949 --- /dev/null +++ b/module02/subject/exercises/m02ex00.tex @@ -0,0 +1,97 @@ +\chapter{Exercise 00} +\extitle{Map, filter, reduce} +\turnindir{ex00} +\exnumber{00} +\exfiles{ft\_map.py, ft\_filter.py, ft\_reduce.py} +\exforbidden{map, filter, reduce} +\makeheaderfilesforbidden + +% ================================== % +\section*{Objective} +% ---------------------------------- % +The goal of this exercise is to work on the built-in functions \texttt{map}, +\texttt{filter} and \texttt{reduce}. + +% ================================== % +\section*{Instructions} +% ---------------------------------- % +Implement the functions \texttt{ft\_map}, \texttt{ft\_filter} and \texttt{ft\_reduce}.\\ +\\ +Take the time to understand the use cases of these two built-in functions +(\texttt{map} and \texttt{filter}) and the function \texttt{reduce} in the functools module.\\ +\\ +You are not expected to code specific classes to create \texttt{ft\_map}, +\texttt{ft\_filter} or \texttt{ft\_reduce} objects, take a closer look +at the examples to know what to do.\\ +\\ +Here are the signatures of the functions:\ +\\ +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} +def ft_map(function_to_apply, iterable): + """Map the function to all elements of the iterable. + Args: + function_to_apply: a function taking an iterable. + iterable: an iterable object (list, tuple, iterator). + Return: + An iterable. + None if the iterable can not be used by the function. + """ + # ... Your code here ... + +def ft_filter(function_to_apply, iterable): + """Filter the result of function apply to all elements of the iterable. + Args: + function_to_apply: a function taking an iterable. + iterable: an iterable object (list, tuple, iterator). + Return: + An iterable. + None if the iterable can not be used by the function. + """ + # ... Your code here ... + +def ft_reduce(function_to_apply, iterable): + """Apply function of two arguments cumulatively. + Args: + function_to_apply: a function taking an iterable. + iterable: an iterable object (list, tuple, iterator). + Return: + A value, of same type of elements in the iterable parameter. + None if the iterable can not be used by the function. + """ + # ... Your code here ... +\end{minted} + +% ================================== % +\section*{Examples} +% ---------------------------------- % + +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} +# Example 1: +x = [1, 2, 3, 4, 5] +ft_map(lambda dum: dum + 1, x) +# Output: + # The adress will be different + +list(ft_map(lambda t: t + 1, x)) +# Output: +[2, 3, 4, 5, 6] + +# Example 2: +ft_filter(lambda dum: not (dum % 2), x) +# Output: + # The adress will be different + +list(ft_filter(lambda dum: not (dum % 2), x)) +# Output: +[2, 4] + +# Example 3: +lst = ['H', 'e', 'l', 'l', 'o', ' ', 'w', 'o', 'r', 'l', 'd'] +ft_reduce(lambda u, v: u + v, lst) +# Output: +"Hello world" +\end{minted} +\\ +You are expected to raise similar exceptions than those of +\texttt{map}, \texttt{filter} and \texttt{reduce} when wrong parameters are given (but no need +to reproduce the exact same exception messages). \ No newline at end of file diff --git a/module02/subject/exercises/m02ex01.tex b/module02/subject/exercises/m02ex01.tex new file mode 100644 index 00000000..86b00276 --- /dev/null +++ b/module02/subject/exercises/m02ex01.tex @@ -0,0 +1,92 @@ +\chapter{Exercise 01} +\extitle{args and kwargs?} +\turnindir{ex01} +\exnumber{01} +\exfiles{main.py} +\exforbidden{None} +\makeheaderfilesforbidden + +% ================================= % +\section*{Objective} +% --------------------------------- % +The goal of this exercise is to discover and manipulate \texttt{*args} and \texttt{**kwargs} arguments. + +% ================================= % +\section*{Instructions} +% --------------------------------- % +In this exercise you have to implement a function named \texttt{what\_are\_the\_vars} +which returns an instance of class ObjectC.\\ +\\ +ObjectC attributes are set via the parameters received during the instanciation. +You will have to modify the 'instance' \texttt{ObjectC}, \textbf{NOT} the class.\\ +\\ +You should take a look at \texttt{getattr}, \texttt{setattr} built-in functions.\\ +\\ +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} +def what_are_the_vars(...): + """ + ... + """ + # ... Your code here ... + +class ObjectC(object): + def __init__(self): + # ... Your code here ... + +def doom_printer(obj): + if obj is None: + print("ERROR") + print("end") + return + for attr in dir(obj): + if attr[0] != '_': + value = getattr(obj, attr) + print("{}: {}".format(attr, value)) + print("end") + +if __name__ == "__main__": + obj = what_are_the_vars(7) + doom_printer(obj) + obj = what_are_the_vars(None, []) + doom_printer(obj) + obj = what_are_the_vars("ft_lol", "Hi") + doom_printer(obj) + obj = what_are_the_vars() + doom_printer(obj) + obj = what_are_the_vars(12, "Yes", [0, 0, 0], a=10, hello="world") + doom_printer(obj) + obj = what_are_the_vars(42, a=10, var_0="world") + doom_printer(obj) + obj = what_are_the_vars(42, "Yes", a=10, var_2="world") + doom_printer(obj) +\end{minted} + +% ================================= % +\section*{Examples} +% --------------------------------- % + +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} +$> python main.py +var_0: 7 +end +var_0: None +var_1: [] +end +var_0: ft_lol +var_1: Hi +end +end +a: 10 +hello: world +var_0: 12 +var_1: Yes +var_2: [0, 0, 0] +end +ERROR +end +a: 10 +var_0: 42 +var_1: Yes +var_2: world +end +\end{minted} diff --git a/module02/subject/exercises/m02ex02.tex b/module02/subject/exercises/m02ex02.tex new file mode 100644 index 00000000..fb0fae4c --- /dev/null +++ b/module02/subject/exercises/m02ex02.tex @@ -0,0 +1,118 @@ +\chapter{Exercise 02} +\extitle{The logger} +\turnindir{ex02} +\exnumber{02} +\exfiles{logger.py} +\exforbidden{None} +\makeheaderfilesforbidden + +% ================================= % +\section*{Objective} +% --------------------------------- % +In this exercise, you will learn about decorators and we are not talking about +the decoration of your room.\\ +\\ +The \texttt{@log} will write info about the decorated function in a +\texttt{machine.log} file.\\ +\\ +% ================================= % +\section*{Instructions} +% --------------------------------- % +You have to create the log decorator in the same file.\\ +\\ +Pay attention to all the different actions logged at the call of +each method. You may notice the username from environment +variables is written to the log file.\\ +\\ + +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} +import time +from random import randint +import os + +#... your definition of log decorator... + +class CoffeeMachine(): + + water_level = 100 + + @log + def start_machine(self): + if self.water_level > 20: + return True + else: + print("Please add water!") + return False + + @log + def boil_water(self): + return "boiling..." + + @log + def make_coffee(self): + if self.start_machine(): + for _ in range(20): + time.sleep(0.1) + self.water_level -= 1 + print(self.boil_water()) + print("Coffee is ready!") + + @log + def add_water(self, water_level): + time.sleep(randint(1, 5)) + self.water_level += water_level + print("Blub blub blub...") + + +if __name__ == "__main__": + + machine = CoffeeMachine() + for i in range(0, 5): + machine.make_coffee() + + machine.make_coffee() + machine.add_water(70) +\end{minted} + +% ================================= % +\section*{Examples} +% --------------------------------- % +\begin{42console} + $> python logger.py + boiling... + Coffee is ready! + boiling... + Coffee is ready! + boiling... + Coffee is ready! + boiling... + Coffee is ready! + Please add water! + Please add water! + Blub blub blub... + $> +\end{42console} + +\begin{42console} + $> cat machine.log + (cmaxime)Running: Start Machine [ exec-time = 0.001 ms ] + (cmaxime)Running: Boil Water [ exec-time = 0.005 ms ] + (cmaxime)Running: Make Coffee [ exec-time = 2.499 s ] + (cmaxime)Running: Start Machine [ exec-time = 0.002 ms ] + (cmaxime)Running: Boil Water [ exec-time = 0.005 ms ] + (cmaxime)Running: Make Coffee [ exec-time = 2.618 s ] + (cmaxime)Running: Start Machine [ exec-time = 0.003 ms ] + (cmaxime)Running: Boil Water [ exec-time = 0.004 ms ] + (cmaxime)Running: Make Coffee [ exec-time = 2.676 s ] + (cmaxime)Running: Start Machine [ exec-time = 0.003 ms ] + (cmaxime)Running: Boil Water [ exec-time = 0.004 ms ] + (cmaxime)Running: Make Coffee [ exec-time = 2.648 s ] + (cmaxime)Running: Start Machine [ exec-time = 0.011 ms ] + (cmaxime)Running: Make Coffee [ exec-time = 0.029 ms ] + (cmaxime)Running: Start Machine [ exec-time = 0.009 ms ] + (cmaxime)Running: Make Coffee [ exec-time = 0.024 ms ] + (cmaxime)Running: Add Water [ exec-time = 5.026 s ] + $> +\end{42console} +Pay attention, the length between ":" and "[" is 20]. +Draw the corresponding conclusions on this part of a log entry. diff --git a/module02/subject/exercises/m02ex03.tex b/module02/subject/exercises/m02ex03.tex new file mode 100644 index 00000000..bcc11085 --- /dev/null +++ b/module02/subject/exercises/m02ex03.tex @@ -0,0 +1,100 @@ +\chapter{Exercise 03} +\extitle{Json issues} +\turnindir{ex03} +\exnumber{03} +\exfiles{csvreader.py} +\exforbidden{None} +\makeheaderfilesforbidden + +% ================================= % +\section*{Objective} +% --------------------------------- % +The goal of this exercise is to implement a context manager as a class.\\ +Thus you are strongly encouraged to do some preliminary research about context manager.\\ + +% ================================= % +\section*{Instructions} +% --------------------------------- % +Implement a \texttt{CsvReader} class that opens, reads, and parses a CSV file.\\ +\ +This class is then a context manager as a class.\\ +\ +In order to create it, your class requires a few built-in methods: +\begin{itemize} + \item \texttt{\_\_init\_\_}, + \item \texttt{\_\_enter\_\_}, + \item \texttt{\_\_exit\_\_}. +\end{itemize} +It is mandatory to close the file once the process is completed. +You are expected to handle properly badly-formatted CSV file (i.e. handle the exception): + +\begin{itemize} + \item mistmatch between number of fields and number of records, + \item records with different lengths. +\end{itemize} + +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} + class CsvReader(): + def __init__(self, filename=None, sep=',', header=False, skip_top=0, skip_bottom=0): + # ... Your code here ... + + def __enter__(...): + # ... Your code here ... + + def __exit__(...): + # ... Your code here ... + + def getdata(self): + """ Retrieves the data/records from skip_top to skip bottom. + Returns: + nested list (list(list, list, ...)) representing the data. + """ + # ... Your code here ... + + def getheader(self): + """ Retrieves the header from the csv file. + Returns: + list: representing the data (when self.header is True). + None: (when self.header is False). + """ + # ... Your code here ... +\end{minted} +\newline +\texttt{CSV} (for Comma-Separated Values) files are delimited text files which use a given character to separate values.\\ +\\ +The separator (or delimiter) is usually a comma (\texttt{,}) or an hyphen comma (\texttt{;}), +but with your context manager you have to offer the possibility to change this parameter.\\ +\\ +One can decide if the class instance skips lines at the top and the bottom of the file via the +parameters \texttt{skip\_top} and \texttt{skip\_bottom}.\\ +\\ +One should also be able to keep the first line as a header if \texttt{header} is \texttt{True}.\\ +\\ +The file should not be corrupted (either a line with too many values or a line +with too few values), otherwise return \texttt{None}.\\ +\\ +You have to handle the case \texttt{file not found}.\\ +\\ +You are expected to implement two methods: +\begin{itemize} + \item \texttt{getdata()}, + \item \texttt{getheader()}. +\end{itemize} + +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} +from csvreader import CsvReader + +if __name__ == "__main__": + with CsvReader('good.csv') as file: + data = file.getdata() + header = file.getheader() +\end{minted} + +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} +from csvreader import CsvReader + +if __name__ == "__main__": + with CsvReader('bad.csv') as file: + if file == None: + print("File is corrupted") +\end{minted} \ No newline at end of file diff --git a/module02/subject/exercises/m02ex04.tex b/module02/subject/exercises/m02ex04.tex new file mode 100644 index 00000000..a4619182 --- /dev/null +++ b/module02/subject/exercises/m02ex04.tex @@ -0,0 +1,94 @@ +\chapter{Exercise 04} +\extitle{MiniPack} +\turnindir{ex04} +\exnumber{04} +\exfiles{build.sh, *.py, *.md, *.cfg, *.txt} +\exforbidden{None} +\makeheaderfilesforbidden + + +% ================================= % +\section*{Objective} +% --------------------------------- % +The goal of this exercise is to learn how to build a package and understand the magnificence of \href{https://pypi.org/}{PyPi}. + +% ================================= % +\section*{Instructions} +% --------------------------------- % +You have to create a package called \texttt{my\_minipack}.\\ +\hint{\href{https://docs.python.org/3.9/distributing/index.html}{RTFM}} +It will have 2 \textbf{modules}: +\begin{itemize} + \item the progress bar (module00 ex10) which should be imported it via \texttt{import my\_minipack.progressbar}, + \item the logger (module02 ex02), which should be imported via \ + \texttt{import my\_minipack.logger}. +\end{itemize} +The package will be installed via pip using one of the following commands (both should work): +\begin{42console} + $> pip install ./dist/my_minipack-1.0.0.tar.gz + $> pip install ./dist/my_minipack-1.0.0-py3-none-any.whl +\end{42console} +\ +Based on the following terminal commands and corresponding outputs, draw the necessary conclusion. +\ +\begin{42console} + $> python -m venv tmp_env && source tmp_env/bin/activate + (tmp_env) > pip list + # Ouput + Package Version + ---------- ------- + pip 19.0.3 + setuptools 40.8.0 + + (tmp_env) $> cd ex04/ && bash build.sh + # Output ... No specific verbose expected, do as you wish ... + ... + (tmp_env) $> ls dist + # Output + my_minipack-1.0.0-py3-none-any.whl my_minipack-1.0.0.tar.gz + + (tmp_env) $> pip list + # Output + Package Version + ----------- ------- + my-minipack 1.0.0 + pip 21.0.1 # the last version at the time + setuptools 54.2.0 # the last version at the time + wheel 0.36.2 # the last version at the time + + (tmp_env) $> pip show -v my_minipack + # Ouput (minimum metadata asked) + Name: my-minipack + Version: 1.0.0 + Summary: Howto create a package in python. + Home-page: None + Author: mdavid + Author-email: mdavid@student.42.fr + License: GPLv3 + Location: [PATH TO BOOTCAMP PYTHON]/module02/tmp_env/lib/python3.7/site-packages + Requires: + Required-by: + Metadata-Version: 2.1 + Installer: pip + Classifiers: + Development Status :: 3 - Alpha + Intended Audience :: Developers + Intended Audience :: Students + Topic :: Education + Topic :: HowTo + Topic :: Package + License :: OSI Approved :: GNU General Public License v3 (GPLv3) + Programming Language :: Python :: 3 + Programming Language :: Python :: 3 :: Only +(tmp_env) $> +\end{42console} +Also add a LICENSE.md (you can choose a real license or a fake one it does not matter) and a README file where you will write a small documentation about your packaged library. +\\ +The `build.sh` script upgrades `pip`, and \textbf{builds} the distribution packages in `wheel` and `egg` formats. +\\ +\info{ +You can check whether the package was properly installed by running the command \texttt{pip list} +that displays the list of installed packages and check the metadata of the package with +\texttt{pip show -v my\_minipack}. +Of course do not reproduce the exact same metadata, change the author information, modify the summary Topic and Audience items if you want to. +} \ No newline at end of file diff --git a/module02/subject/exercises/m02ex05.tex b/module02/subject/exercises/m02ex05.tex new file mode 100644 index 00000000..1ab549c3 --- /dev/null +++ b/module02/subject/exercises/m02ex05.tex @@ -0,0 +1,71 @@ +\chapter{Exercise 05} +\extitle{TinyStatistician} +\turnindir{ex05} +\exnumber{05} +\exfiles{TinyStatistician.py} +\exforbidden{Any function that calculates mean, median, quartiles, variance or standar deviation for you.} +\makeheaderfilesforbidden + + +% ================================= % +\section*{Objective} +% --------------------------------- % +Initiation to very basic statistic notions. + +% ================================= % +\section*{Instructions} +% --------------------------------- % +Create a class named \texttt{TinyStatistician} that implements the following methods: +\begin{itemize} + \item \texttt{mean(x)}: computes the mean of a given non-empty list or array \texttt{x}, using a for-loop. + The method returns the mean as a float, otherwise \texttt{None} if \texttt{x} is an empty list or array. + Given a vector \texttt{x} of dimension $m \times 1$, the mathematical formula of its mean is: + $$ + \mu = \frac{\sum_{i = 1}^{m}{x_i}}{m} + $$ + \item \texttt{median(x)}: computes the median of a given non-empty list or array \texttt{x}. + The method returns the median as a float, otherwise \texttt{None} if \texttt{x} is an empty list or array. + \item \texttt{quartiles(x)}: computes the $1^{\text{st}}$ and $3^{\text{rd}}$ quartiles of a given non-empty array \texttt{x}. + The method returns the quartile as a float, otherwise \texttt{None} if \texttt{x} is an empty list or array. + \item \texttt{var(x)}: computes the variance of a given non-empty list or array \texttt{x}, using a for-loop. + The method returns the variance as a float, otherwise \texttt{None} if \texttt{x} is an empty list or array. + Given a vector \texttt{x} of dimension $m \times 1$, the mathematical formula of its variance is: + $$ + \sigma^2 = \frac{\sum_{i = 1}^{m}{(x_i - \mu)^2}}{m} = \frac{\sum_{i = 1}^{m}{[x_i - (\frac{1}{m}\sum_{j = 1}^{m}{x_j}})]^2}{m} + $$ + \item \texttt{std(x)} : computes the standard deviation of a given non-empty list or array \texttt{x}, using a for-loop. + The method returns the standard deviation as a float, otherwise \texttt{None} if \texttt{x} is an empty list or array. + Given a vector \texttt{x} of dimension $m \times 1$, the mathematical formula of its standard deviation is: + $$ + \sigma = \sqrt{\frac{\sum_{i = 1}^{m}{(x_i - \mu)^2}}{m}} = \sqrt{\frac{\sum_{i = 1}^{m}{[x_i - (\frac{1}{m}\sum_{j = 1}^{m}{x_j}})]^2}{m}} + $$ +\end{itemize} +All methods take a \texttt{list} or a \texttt{numpy.ndarray} as parameter.\\ +\\ +We are assuming that all inputs have a correct format, i.e. a list or array of numeric type or empty list or array.\\ +\\ +You don't have to protect your functions against input errors. +\\ +% ================================= % +\section*{Examples} +% --------------------------------- % +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} +from TinyStatistician import TinyStatistician +tstat = TinyStatistician() +a = [1, 42, 300, 10, 59] + +tstat.mean(a) +# Expected result: 82.4 + +tstat.median(a) +# Expected result: 42.0 + +tstat.quartile(a) +# Expected result: [10.0, 59.0] + +tstat.var(a) +# Expected result: 12279.439999999999 + +tstat.std(a) +# Expected result: 110.81263465868862 +\end{minted} \ No newline at end of file diff --git a/module03/assets/elon_celluloid2.png b/module03/assets/elon_celluloid2.png new file mode 100644 index 00000000..1d8fb81d Binary files /dev/null and b/module03/assets/elon_celluloid2.png differ diff --git a/module03/exercises/m03ex00.tex b/module03/exercises/m03ex00.tex new file mode 100644 index 00000000..d36a7dd6 --- /dev/null +++ b/module03/exercises/m03ex00.tex @@ -0,0 +1,101 @@ +\chapter{Exercise 00} +\extitle{NumPyCreator} +\turnindir{ex00} +\exnumber{00} +\exfiles{NumPyCreator.py} +\exforbidden{None} +\makeheaderfilesforbidden + +% ================================== % +\section*{Objective} +% ---------------------------------- % +Introduction to the Numpy library. + +% ================================== % +\section*{Instructions} +% ---------------------------------- % +Write a class named \texttt{NumPyCreator}, that implements all of the following methods.\\ +\\ +Each method receives as an argument a different type of data structure and transforms it into a Numpy array: +\begin{itemize} + \item \texttt{from\_list(self, lst)}: takes a list or nested lists and returns its corresponding Numpy array. + \item \texttt{from\_tuple(self, tpl)}: takes a tuple or nested tuples and returns its corresponding Numpy array. + \item \texttt{from\_iterable(self, itr)}: takes an iterable and returns an array which contains all of its elements. + \item \texttt{from\_shape(self, shape, value)}: returns an array filled with the same value. + The first argument is a tuple which specifies the shape of the array, and the second argument specifies the value of the elements. + This value must be 0 by default. + \item \texttt{random(self, shape)}: returns an array filled with random values. + It takes as an argument a tuple which specifies the shape of the array. + \item \texttt{identity(self, n)}: returns an array representing the identity matrix of size n. +\end{itemize} +\textit{\textbf{BONUS:}} Add to these methods an optional argument which specifies the datatype (dtype) of the array (e.g. to represent its elements as integers, floats, ...) + +\hint{Each of these methods can be implemented in one line. You only need to find the right Numpy functions.} + +% ================================== % +\section*{Examples} +% ---------------------------------- % +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} +from NumpyCreator import NumpyCreator +npc = NumpyCreator() + +npc.from_list([[1,2,3],[6,3,4]]) +# Output : +array([[1, 2, 3], + [6, 3, 4]]) + + +npc.from_list([[1,2,3],[6,4]]) +# Output : +None + + +npc.from_list([[1,2,3],['a','b','c'],[6,4,7]]) +# Output : +array([['1','2','3'], + ['a','b','c'], + ['6','4','7'], dtype='}, \texttt{\&} (or \texttt{and}). + \end{itemize} + \item \texttt{to\_grayscale}: + \begin{itemize} + \item Authorized functions: \texttt{.sum},\texttt{.shape},\texttt{.reshape},\texttt{.broadcast\_to},\texttt{.as\_type}. + \item Authorized operators: \texttt{*},\texttt{/}, \texttt{=}. + \end{itemize} +\end{itemize} +% ================================= % +\section*{Examples} +% --------------------------------- % +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} +from ImageProcessor import ImageProcessor +imp = ImageProcessor() +arr = imp.load("assets/42AI.png") +# Output : +Loading image of dimensions 200 x 200 + + +from ColorFilter import ColorFilter +cf = ColorFilter() +cf.invert(arr) + +cf.to_green(arr) + +cf.to_red(arr) + +cf.to_blue(arr) + +cf.to_celluloid(arr) + +cf.to_grayscale(arr, 'm') + +cf.to_grayscale(arr, 'weight', r_weight=0.2, 'g_weight'=0.3, 'b_weight'=0.5) +\end{minted} + +\begin{figure}[h!] + \begin{minipage}[l]{0.49\linewidth} + \includegraphics[scale=0.38]{assets/elon_canaGAN.png} + \vspace{-50pt} + \caption{Elon Musk} + \end{minipage} + \hfill + \begin{minipage}[c]{0.49\linewidth} + \includegraphics[scale=0.38]{assets/elon_inverted.png} + \vspace{-50pt} + \caption{Inverted filter} + \end{minipage} + \vspace{-20pt} + \begin{minipage}[l]{0.49\linewidth} + \includegraphics[scale=0.38]{assets/elon_blue.png} + \vspace{-50pt} + \caption{Blue filter} + \end{minipage} + \hfill + \begin{minipage}[c]{0.49\linewidth} + \includegraphics[scale=0.38]{assets/elon_green.png} + \vspace{-50pt} + \caption{Green filter} + \end{minipage} + \vspace{-20pt} + \begin{minipage}[l]{0.49\linewidth} + \includegraphics[scale=0.38]{assets/elon_red.png} + \vspace{-50pt} + \caption{Red filter} + \end{minipage} + \hfill + \begin{minipage}[c]{0.49\linewidth} + \includegraphics[scale=0.38]{assets/elon_celluloid.png} + \vspace{-50pt} + \caption{Celluloid filter} + \end{minipage} + +\end{figure} + +\info{ +The first image is a stylization of Elon Musk that has been generated using a style transfer algorithm implemented in our lab. +You can see the code in 42AI repository \href{https://github.com/42-AI/StyleTransferMirror}{StyleTransferMirror}} diff --git a/module03/exercises/m03ex04.tex b/module03/exercises/m03ex04.tex new file mode 100644 index 00000000..b491be61 --- /dev/null +++ b/module03/exercises/m03ex04.tex @@ -0,0 +1,134 @@ +\chapter{Exercise 04} +\extitle{K-means Clustering} +\turnindir{ex04} +\exnumber{04} +\exfiles{Kmeans.py} +\exforbidden{Any functions allowing you to perform K-Means} +\makeheaderfilesforbidden + +ALERT! DATA CORRUPTED + +% ================================= % +\section*{Objective} +% --------------------------------- % +Implementation of a basic K-means algorithm. + +% ================================= % +\section*{Instructions} +% --------------------------------- % +The solar system census dataset is corrupted! The citizens' homelands are missing!\\ +\\ +You must implement the K-means clustering algorithm in order to recover the citizens' origins.\\ +\\ +You can find good explanations on how K-means is working here: +\href{https://en.wikipedia.org/wiki/K-means_clustering}{Wikipedia - K-Means clustering}\\ +\\ +The missing part is how to compute the distance between 2 data points (cluster centroid or a row in the data).\\ +\\ +In our case, the data we have to process is composed of 3 values (height, weight and bone\_density).\\ +\\ +Thus, each data point is a vector of 3 values.\\ +\\ +Now that we have mathematically defined our data points (vector of 3 values), it is very easy to compute the distance between two points using vector properties.\\ +You can use L1 distance, L2 distance, cosine similarity, and so forth...\\ +Choosing the distance to use is called hyperparameter tuning.\\ +\newline +I would suggest you to try with the easiest setting (L1 distance) first.\\ +\\ +What you will notice is that the final result of the "training"/"fitting" will depend a lot on the random initialization.\\ +\\ +Commonly, in machine-learning libraries, K-means is run multiple times (with different random initializations) and the best result is saved.\\ +\\ +NB: To implement the fit function, keep in mind that a centroid can be considered as the gravity center of a set of points.\\ +\\ +Your program \texttt{Kmeans.py} takes 3 parameters: \texttt{filepath}, \texttt{max\_iter} and \texttt{ncentroid}: + +\begin{42console} + python Kmeans.py filepath='../ressources/solar_system_census.csv' ncentroid=4 max_iter=30 +\end{42console} + +Your program is expected to: +\begin{itemize} + \item parse its arguments, + \item read the dataset, + \item fit the dataset, + \item display the coordinates of the different centroids and the associated region (for the case \texttt{ncentroid=4}), + \item display the number of individuals associated to each centroid, + \item (Optional) display the results on 3 differents plots, corresponding to 3 combinations of 2 parameters, using different colors to distinguish between Venus,Earth, Mars and Belt asteroids citizens. +\end{itemize} + +Create the class \texttt{KmeansClustering} with the following methods: + +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} +class KmeansClustering: + def __init__(self, max_iter=20, ncentroid=5): + self.ncentroid = ncentroid # number of centroids + self.max_iter = max_iter # number of max iterations to update the centroids + self.centroids = [] # values of the centroids + + def fit(self, X): + """ + Run the K-means clustering algorithm. + For the location of the initial centroids, randomly pick n centroids from the dataset. + Args: + ----- + X: has to be an numpy.ndarray, a matrice of dimension m * n. + Return: + ------- + None. + Raises: + ------- + This function should not raise any Exception. + """ + ... your code ... + + def predict(self, X): + """ + Predict from wich cluster each datapoint belongs to. + Args: + ----- + X: has to be an numpy.ndarray, a matrice of dimension m * n. + Return: + ------- + the prediction has a numpy.ndarray, a vector of dimension m * 1. + Raises: + ------- + This function should not raise any Exception. + """ + ... your code ... +\end{minted} + +% ================================= % +\section*{Dataset} +% --------------------------------- % +The dataset, named \textbf{solar\_system\_census} can be found in +the resources folder.\\ +\\ +It is a part of the solar system census dataset, and contains biometric +data such as the height, weight, and bone density of solar +system citizens.\\ +\\ +Solar citizens come from four registered areas: +\begin{itemize} + \item The flying cities of Venus, + \item United Nations of Earth, + \item Mars Republic, + \item Asteroids' Belt colonies. +\end{itemize} +Unfortunately the data about the planets of origin was lost...\\ +Use your K-means algorithm to recover it!\\ +Once your clusters are found, try to find matches between clusters and the citizens' homelands.\\ + +\hint{ + \begin{itemize} + \item People are slender on Venus than on Earth. + \item People of the Martian Republic are taller than on Earth. + \item Citizens of the Belt are the tallest of the solar system and have the lowest bone density due to the lack of gravity. + \end{itemize} +} + +% ================================= % +\section*{Examples} +% --------------------------------- % +Here is an example of the K-means algorithm in action:\\ +\url{https://i.ibb.co/bKFVVx2/ezgif-com-gif-maker.gif} \ No newline at end of file diff --git a/module03/subject/assets/42ai_logo.pdf b/module03/subject/assets/42ai_logo.pdf index c915fc5c..1f5d3abb 100644 Binary files a/module03/subject/assets/42ai_logo.pdf and b/module03/subject/assets/42ai_logo.pdf differ diff --git a/module03/subject/en.acknowledgements.tex b/module03/subject/en.acknowledgements.tex new file mode 100644 index 00000000..2647117e --- /dev/null +++ b/module03/subject/en.acknowledgements.tex @@ -0,0 +1,38 @@ +\section*{Contact} +% --------------------------------- % +You can contact 42AI by email: \href{mailto:contact@42ai.fr}{contact@42ai.fr}\\ +\newline +Thank you for attending 42AI's Python Bootcamp module03 ! + +% ================================= % +\section*{Acknowledgements} +% --------------------------------- % +The Python bootcamp is the result of a collective work, for which we would like to thank: +\begin{itemize} + \item Maxime Choulika (cmaxime), + \item Pierre Peigné (ppeigne, pierre@42ai.fr), + \item Matthieu David (mdavid, matthieu@42ai.fr), + \item Quentin Feuillade--Montixi (qfeuilla, quentin@42ai.fr) + \item Mathieu Perez (maperez, mathieu.perez@42ai.fr) +\end{itemize} +who supervised the creation, the enhancement of the bootcamp and this present transcription. + +\begin{itemize} + \item Louis Develle (ldevelle, louis@42ai.fr) + \item Augustin Lopez (aulopez) + \item Luc Lenotre (llenotre) + \item Owen Roberts (oroberts) + \item Thomas Flahault (thflahau) + \item Amric Trudel (amric@42ai.fr) + \item Baptiste Lefeuvre (blefeuvr@student.42.fr) + \item Mathilde Boivin (mboivin@student.42.fr) + \item Tristan Duquesne (tduquesn@student.42.fr) +\end{itemize} +for your investment in the creation and development of these modules. + +\begin{itemize} + \item All prior participants who took a moment to provide their feedbacks, and help us improve these bootcamps ! +\end{itemize} + + \vfill +\doclicenseThis \ No newline at end of file diff --git a/module03/subject/en.instructions.tex b/module03/subject/en.instructions.tex new file mode 100644 index 00000000..37463d60 --- /dev/null +++ b/module03/subject/en.instructions.tex @@ -0,0 +1,36 @@ +\chapter{Common Instructions} +\begin{itemize} + \item The version of Python recommended to use is 3.7, you can + check the version of Python with the following command: \texttt{python -V} + + \item The norm: during this bootcamp, it is recommended to follow the + \href{https://www.python.org/dev/peps/pep-0008/}{PEP 8 standards}, though it is not mandatory. + You can install \href{https://pypi.org/project/pycodestyle}{pycodestyle} which + is a tool to check your Python code. + \item The function \texttt{eval} is never allowed. + \item The exercises are ordered from the easiest to the hardest. + \item Your exercises are going to be evaluated by someone else, + so make sure that your variable names and function names are appropriate and civil. + \item Your manual is the internet. + + \item If you are a student from 42, you can access our Discord server + on \href{https://discord.com/channels/887850395697807362/887850396314398720}{42 student's associations portal} and ask your + questions to your peers in the dedicated Bootcamp channel. + + \item You can learn more about 42 Artificial Intelligence by visiting \href{https://42-ai.github.io}{our website}. + + \item If you find any issue or mistake in the subject please create an issue on \href{https://github.com/42-AI/bootcamp_python/issues}{42AI repository on Github}. + + \item We encourage you to create test programs for your + project even though this work \textbf{won't have to be + submitted and won't be graded}. It will give you a chance + to easily test your work and your peers’ work. You will find + those tests especially useful during your defence. Indeed, + during defence, you are free to use your tests and/or the + tests of the peer you are evaluating. + + \item We are constantly looking to improve these bootcamps, and your feedbacks are essential for us to do so !\\ + You can tell us more about your experience with this module by filling \href{https://forms.gle/mBe7sBKq9tJzpDG37}{this form}.\\ + Thank you in advance and good luck for this bootcamp ! + +\end{itemize} \ No newline at end of file diff --git a/module03/subject/en.py_proj.tex b/module03/subject/en.py_proj.tex deleted file mode 100644 index 95cf19ca..00000000 --- a/module03/subject/en.py_proj.tex +++ /dev/null @@ -1,45 +0,0 @@ -%******************************************************************************% -% % -% Common Instructions % -% for Python Projects % -% % -%******************************************************************************% - -\chapter{Common Instructions} -\begin{itemize} - \item The version of Python recommended to use is 3.7, you can - check the version of Python with the following command: \texttt{python -V} - - \item The norm: during this bootcamp you will follow the - \href{https://www.python.org/dev/peps/pep-0008/}{PEP 8 standards}. - You can install \href{https://pypi.org/project/pycodestyle}{pycodestyle} which - is a tool to check your Python code. - - \item The function \texttt{eval} is never allowed. - - \item The exercises are ordered from the easiest to the hardest. - - \item Your exercises are going to be evaluated by someone else, - so make sure that your variable names and function names are appropriate and civil. - - \item Your manual is the internet. - - \item You can also ask questions in the \texttt{\#bootcamps} channel in the \href{https://42-ai.slack.com}{42AI} - or \href{42born2code.slack.com}{42born2code}. - - \item If you find any issue or mistakes in the subject please create an issue on \href{https://github.com/42-AI/bootcamp_python/issues}{42AI repository on Github}. - - \item We encourage you to create test programs for your - project even though this work \textbf{won't have to be - submitted and won't be graded}. It will give you a chance - to easily test your work and your peers’ work. You will find - those tests especially useful during your defence. Indeed, - during defence, you are free to use your tests and/or the - tests of the peer you are evaluating. - - \item Submit your work to your assigned git repository. Only the work in the - git repository will be graded. If Deepthought is assigned to grade your - work, it will be run after your peer-evaluations. - If an error happens in any section of your work during Deepthought's grading, - the evaluation will stop. -\end{itemize} \ No newline at end of file diff --git a/module03/subject/en.subject.pdf b/module03/subject/en.subject.pdf new file mode 100644 index 00000000..aa129ce8 Binary files /dev/null and b/module03/subject/en.subject.pdf differ diff --git a/module03/subject/en.subject.pdf.version b/module03/subject/en.subject.pdf.version deleted file mode 100644 index 56a6051c..00000000 --- a/module03/subject/en.subject.pdf.version +++ /dev/null @@ -1 +0,0 @@ -1 \ No newline at end of file diff --git a/module03/subject/en.subject.tex b/module03/subject/en.subject.tex index 160fcc74..95e059e0 100644 --- a/module03/subject/en.subject.tex +++ b/module03/subject/en.subject.tex @@ -117,7 +117,7 @@ % =============================================================================% % ===================================== % -\title{Python \& ML - Module 03} +\title{Python Bootcamp - Module 03} \subtitle{Numpy} \author{ Maxime Choulika (cmaxime), Pierre Peigné (ppeigne), Matthieu David (mdavid) @@ -130,7 +130,7 @@ } \maketitle -\input{en.py_proj.tex} +\input{en.instructions.tex} \newpage \tableofcontents \startexercices @@ -147,824 +147,36 @@ % ============================================== % % ===========================(start ex 00) % -\chapter{Exercise 00} -\extitle{NumPyCreator} -\turnindir{ex00} -\exnumber{00} -\exfiles{NumPyCreator.py} -\exforbidden{None} -\makeheaderfilesforbidden - -% ================================== % -\section*{Objective} -% ---------------------------------- % -Introduction to Numpy library. - -% ================================== % -\section*{Instructions} -% ---------------------------------- % -Write a class named \texttt{NumPyCreator}, that implements all of the following methods. -Each method receives as an argument a different type of data structure and transforms it into a Numpy array: -\begin{itemize} - \item \texttt{from\_list(lst)}: takes a list or nested lists and returns its corresponding Numpy array. - \item \texttt{from\_tuple(tpl)}: takes a tuple or nested tuples and returns its corresponding Numpy array. - \item \texttt{from\_iterable(itr)}: takes an iterable and returns an array which contains all its elements. - \item \texttt{from\_shape(shape, value)}: returns an array filled with the same value. - The first argument is a tuple which specifies the shape of the array, and the second argument specifies the value of the elements. - This value must be 0 by default. - \item \texttt{random(shape)}: returns an array filled with random values. - It takes as an argument a tuple which specifies the shape of the array. - \item \texttt{identity(n)}: returns an array representing the identity matrix of size n. -\end{itemize} - - -\textit{\textbf{BONUS:}} Add to those methods an optional argument which specifies the datatype (dtype) of the array (e.g. to represent its elements as integers, floats, ...) - -\hint All those methods can be implemented in one line. You only need to find the right Numpy functions. - -% ================================== % -\section*{Examples} -% ---------------------------------- % -\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} -from NumpyCreator import NumpyCreator -npc = NumpyCreator() - -npc.from_list([[1,2,3],[6,3,4]]) -# Output : -array([[1, 2, 3], - [6, 3, 4]]) - - -npc.from_list([[1,2,3],[6,4]]) -# Output : -None - - -npc.from_list([[1,2,3],['a','b','c'],[6,4,7]]) -# Output : -array([['1','2','3'], - ['a','b','c'], - ['6','4','7'], dtype='50K +8 31 Private 45781 ... 50 United-States >50K +9 42 Private 159449 ... 40 United-States >50K +10 37 Private 280464 ... 80 United-States >50K +11 30 State-gov 141297 ... 40 India >50K + +[12 rows x 15 columns] +\end{minted} + +\hint{NB: Your terminal may display more columns if the window is wider.} \ No newline at end of file diff --git a/module04/exercises/m04ex01.tex b/module04/exercises/m04ex01.tex new file mode 100644 index 00000000..3dd950e2 --- /dev/null +++ b/module04/exercises/m04ex01.tex @@ -0,0 +1,45 @@ +\chapter{Exercise 01} +\extitle{YoungestFellah} +\turnindir{ex01} +\exnumber{01} +\exfiles{FileLoader.py, YoungestFellah.py} +\exforbidden{None} +\makeheaderfilesforbidden + + +% ================================= % +\section*{Objective} +% --------------------------------- % +The goal of this exercise is to create a function that will return a +dictionary containing the age of the youngest woman and the youngest +man who took part in the Olympics for a given year. + +% ================================= % +\section*{Instructions} +% --------------------------------- % +This exercise uses the following dataset: \texttt{athlete\_events.csv}.\\ +\\ +Write a function \texttt{youngest\_fellah} that takes two arguments: +\begin{itemize} + \item a pandas.DataFrame which contains the dataset + \item an Olympic year. +\end{itemize} +The function returns a dictionary containing the age of the youngest +woman and man who took part in the Olympics on that year. +The names of the dictionary's keys are up to you, but they must be explicit and self-explanatory. + +% ================================= % +\section*{Examples} +% --------------------------------- % +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} +from FileLoader import FileLoader +loader = FileLoader() +data = loader.load('../data/athlete_events.csv') +# Output +Loading dataset of dimensions 271116 x 15 + +from YoungestFellah import youngest_fellah +youngest_fellah(data, 2004) +# Output +{'f': 13.0, 'm': 14.0} +\end{minted} diff --git a/module04/exercises/m04ex02.tex b/module04/exercises/m04ex02.tex new file mode 100644 index 00000000..7c4bc52f --- /dev/null +++ b/module04/exercises/m04ex02.tex @@ -0,0 +1,58 @@ +\chapter{Exercise 02} +\extitle{ProportionBySport} +\turnindir{ex02} +\exnumber{02} +\exfiles{FileLoader.py, ProportionBySport.py} +\exforbidden{None} +\makeheaderfilesforbidden + +% ================================= % +\section*{Objective} +% --------------------------------- % +The goal of this exercise is to create a function displaying +the proportion of participants who played a given sport, among +the participants of a given gender. + +% ================================= % +\section*{Instructions} +% --------------------------------- % +This exercise uses the dataset \texttt{athlete\_events.csv}. + +Write a function \texttt{proportion\_by\_sport} that takes four arguments: +\begin{itemize} + \item a pandas.DataFrame of the dataset, + \item an olympic year, + \item a sport, + \item a gender. +\end{itemize} +The function returns a float corresponding to the proportion (percentage) of participants +who played the given sport among the participants of the given gender.\\ +\\ +The function answers questions like the following : +"What was the percentage of female basketball players among all female +participants in the 2016 Olympics?" + +\hint{ +Here and later on, if needed, drop duplicate sports people to count only unique ones. Beware to call the dropping function +at the right moment and with the right parameters, in order not to omit any individual. +} + +% ================================= % +\section*{Examples} +% --------------------------------- % +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} +from FileLoader import FileLoader +loader = FileLoader() +data = loader.load('../data/athlete_events.csv') +# Output +Loading dataset of dimensions 271116 x 15 + + +from ProportionBySport import proportion_by_sport +proportion_by_sport(data, 2004, 'Tennis', 'F') +# Output +0.019302325581395347 +\end{minted} +\newline +We assume that we are always using valid arguments as input, +and thus do not need to handle input errors. \ No newline at end of file diff --git a/module04/exercises/m04ex03.tex b/module04/exercises/m04ex03.tex new file mode 100644 index 00000000..4735b749 --- /dev/null +++ b/module04/exercises/m04ex03.tex @@ -0,0 +1,56 @@ +\chapter{Exercise 03} +\extitle{HowManyMedals} +\turnindir{ex03} +\exnumber{03} +\exfiles{FileLoader.py, HowManyMedals.py} +\exforbidden{None} +\makeheaderfilesforbidden + + +% ================================= % +\section*{Objective} +% --------------------------------- % +The goal of this exercise is to implement a function that will return +a dictionary of dictionaries giving the number and types of medals +for each year during which the participant won medals. + +% ================================= % +\section*{Instructions} +% --------------------------------- % +This exercise uses the following dataset: \texttt{athlete\_events.csv}. + + +Write a function \texttt{how\_many\_medals} that takes two arguments: +\begin{itemize} + \item a pandas.DataFrame which contains the dataset, + \item a participant's name. +\end{itemize} +The function returns a dictionary of dictionaries giving the number and type of medals +for each year during which the participant won medals.\\ +\\ +The keys of the main dictionary are the years of the Olympic games.\\ +\\ +In each year's dictionary, the keys are 'G', 'S', 'B' corresponding to the type of +medals won (Gold, Silver, Bronze).\ +The innermost values correspond to the number of medals of a given type won for a given year. + +% ================================= % +\section*{Examples} +% --------------------------------- % +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} +from FileLoader import FileLoader +loader = FileLoader() +data = loader.load('../data/athlete_events.csv') +# Output +Loading dataset of dimensions 271116 x 15 + + +from HowManyMedals import how_many_medals +how_many_medals(data, 'Kjetil Andr Aamodt') +# Output +{1992: {'G': 1, 'S': 0, 'B': 1}, + 1994: {'G': 0, 'S': 2, 'B': 1}, + 1998: {'G': 0, 'S': 0, 'B': 0}, + 2002: {'G': 2, 'S': 0, 'B': 0}, + 2006: {'G': 1, 'S': 0, 'B': 0}} +\end{minted} \ No newline at end of file diff --git a/module04/exercises/m04ex04.tex b/module04/exercises/m04ex04.tex new file mode 100644 index 00000000..aab0f34b --- /dev/null +++ b/module04/exercises/m04ex04.tex @@ -0,0 +1,62 @@ +\chapter{Exercise 04} +\extitle{SpatioTemporalData} +\turnindir{ex04} +\exnumber{04} +\exfiles{FileLoader.py, SpatioTemporalData.py} +\exforbidden{None} +\makeheaderfilesforbidden + + +% ================================= % +\section*{Objective} +% --------------------------------- % +The goal of this exercise is to implement a class called \texttt{SpatioTemporalData} +that takes a dataset (pandas.DataFrame) as argument in its constructor +and implements two methods. +% ================================= % +\section*{Instructions} +% --------------------------------- % +This exercise uses the dataset \texttt{athlete\_events.csv}.\\ +\\ +Write a class called \texttt{SpatioTemporalData} that takes a dataset +(pandas.DataFrame) as argument in its constructor and implements the +following methods: +\begin{itemize} + \item \texttt{when(location)}: takes a location as an argument and returns + a list containing the years where games were held in the given location, + \item \texttt{where(date)}: takes a date as an argument and returns the location + where the Olympics took place in the given year. +\end{itemize} + +% ================================= % +\section*{Examples} +% --------------------------------- % +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} +from FileLoader import FileLoader +loader = FileLoader() +data = loader.load('../data/athlete_events.csv') +# Output +Loading dataset of dimensions 271116 x 15 + + +from SpatioTemporalData import SpatioTemporalData +sp = SpatioTemporalData(data) +sp.where(1896) +# Output +['Athina'] + + +sp.where(2016) +# Output +['Rio de Janeiro'] + + +sp.when('Athina') +# Output +[2004, 1906, 1896] + + +sp.when('Paris') +# Output +[1900, 1924] +\end{minted} \ No newline at end of file diff --git a/module04/exercises/m04ex05.tex b/module04/exercises/m04ex05.tex new file mode 100644 index 00000000..cec70979 --- /dev/null +++ b/module04/exercises/m04ex05.tex @@ -0,0 +1,70 @@ +\chapter{Exercise 05} +\extitle{HowManyMedalsByCountry} +\turnindir{ex05} +\exnumber{05} +\exfiles{FileLoader.py, HowManyMedalsByCountry.py} +\exforbidden{None} +\makeheaderfilesforbidden + + +% ================================= % +\section*{Objective} +% --------------------------------- % +The goal of this exercise is to write a function that returns a +dictionary of dictionaries giving the number and types of medals for +each competition where a given country delegation earned medals. + +% ================================= % +\section*{Instructions} +% --------------------------------- % +This exercise uses the following dataset: \texttt{athlete\_events.csv}\\ +\\ +Write a function \texttt{how\_many\_medals\_by\_country} that takes two arguments: +\begin{itemize} + \item a pandas.DataFrame which contains the dataset + \item a country name. +\end{itemize} +The function returns a dictionary of dictionaries giving the number and +types of medals for each competition where the country delegation earned medals.\\ +\\ +The keys of the main dictionary are the Olympic games' years. In each +year's dictionary, the keys are 'G', 'S', 'B' corresponding to the +types of medals won. +\\ +Duplicated medals per team games should be handled and not counted twice.\\ +\\ +Hint: You may find this list to be of some use. + +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} + team_sports = ['Basketball', 'Football', 'Tug-Of-War', 'Badminton', 'Sailing', + 'Handball', 'Water Polo', 'Hockey', 'Rowing', 'Bobsleigh', 'Softball', + 'Volleyball', 'Synchronized Swimming', 'Baseball', 'Rugby Sevens', + 'Rugby', 'Lacrosse', 'Polo'] +\end{minted} + +% ================================= % +\section*{Examples} +% --------------------------------- % +\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} +from FileLoader import FileLoader +loader = FileLoader() +data = loader.load('../data/athlete_events.csv') +# Output +Loading dataset of dimensions 271116 x 15 + + +from HowManyMedalsByCountry import how_many_medals_by_country +how_many_medals_by_country(data, 'Martian Federation') +# Output +{2192: {'G': 17, 'S': 14, 'B': 23}, 2196: {'G': 8, 'S': 21, 'B': 19}, 2200: {'G': 26, 'S': 19, 'B': 7}} +\end{minted} +\newline +You probably guessed by now that we gave up providing real examples...\\ +\\ +If you want real examples, you can easily look online.\\ +\\ +Do beware that some medals might be awarded or removed years after the games +are over, for example if a previous medallist was found to have cheated.\\ +\\ +The \texttt{athlete\_events.csv} dataset might not always take these posterior +changes into account. \ No newline at end of file diff --git a/module04/exercises/m04ex06.tex b/module04/exercises/m04ex06.tex new file mode 100644 index 00000000..49c43ea0 --- /dev/null +++ b/module04/exercises/m04ex06.tex @@ -0,0 +1,62 @@ +\chapter{Exercise 06} +\extitle{MyPlotLib} +\turnindir{ex06} +\exnumber{06} +\exfiles{MyPlotLib.py} +\exforbidden{None} +\makeheaderfilesforbidden + +% ================================= % +\section*{Objective} +% --------------------------------- % +The goal of this exercise is to introduce you to plotting methods using different +libraries like Pandas, Matplotlib, Seaborn or Scipy. + +% ================================= % +\section*{Instructions} +% --------------------------------- % +This exercise uses the following dataset: \texttt{athlete\_events.csv}\\ +\\ +Write a class called \texttt{MyPlotLib}. This class implements different plotting +methods, each of which takes two arguments: +\begin{itemize} + \item a pandas.DataFrame which contains the dataset, + \item a list of features names. +\end{itemize} + +\hint{\href{https://towardsdatascience.com/feature-engineering-for-machine-learning-3a5e293a5114}{What is a feature?}} + +\begin{itemize} + \item \texttt{histogram(data, features)}: plots one histogram for each numerical feature in the list, + \item \texttt{density(data, features)}: plots the density curve of each numerical feature in the list, + \item \texttt{pair\_plot(data, features)}: plots a matrix of subplots (also called scatter plot matrix). + On each subplot shows a scatter plot of one numerical variable against another one. + The main diagonal of this matrix shows simple histograms. + \item \texttt{box\_plot(data, features)}: displays a box plot for each numerical variable in the dataset. +\end{itemize} + +% ================================= % +\section*{Examples} +% --------------------------------- % + +\begin{figure}[h!] + \begin{minipage}[l]{0.49\linewidth} + \includegraphics[scale=0.39]{assets/ex06_histogram.png} + \caption{histogram} + \end{minipage} + \hfill + \begin{minipage}[c]{0.49\linewidth} + \includegraphics[scale=0.39]{assets/ex06_density.png} + \caption{density} + \end{minipage} + + \begin{minipage}[l]{0.49\linewidth} + \includegraphics[scale=0.39]{assets/ex06_pair_plot.png} + \caption{pair plot} + \end{minipage} + \hfill + \begin{minipage}[c]{0.49\linewidth} + \includegraphics[scale=0.39]{assets/ex06_box_plot.png} + \caption{box plot} + \end{minipage} +\end{figure} \ No newline at end of file diff --git a/module04/exercises/m04ex07.tex b/module04/exercises/m04ex07.tex new file mode 100644 index 00000000..3b6731d8 --- /dev/null +++ b/module04/exercises/m04ex07.tex @@ -0,0 +1,36 @@ +\chapter{Exercise 07} +\extitle{Komparator} +\turnindir{ex07} +\exnumber{07} +\exfiles{Komparator.py, MyPlotLib.py (optional)} +\exforbidden{None} +\makeheaderfilesforbidden + + +% ================================= % +\section*{Objective} +% --------------------------------- % +The goal of this exercise is to introduce plotting methods among the different +libraries Pandas, Matplotlib, Seaborn or Scipy. + +% ================================= % +\section*{Instructions} +% --------------------------------- % +This exercise uses the following dataset: \texttt{athlete\_events.csv}.\\ +\\ +Write a class called \texttt{Komparator} whose constructor takes as an argument a pandas.DataFrame which contains the dataset.\\ +\\ +The class must implement the following methods, which take as input two variable names: +\begin{itemize} + \item \texttt{compare\_box\_plots(self, categorical\_var, numerical\_var)}: displays a series of box plots + to compare how the distribution of the numerical variable changes if we only consider + the subpopulation which belongs to each category. + There should be as many box plots as categories. + For example, with Sex and Height, we would compare + the height distributions of men vs. women with two box plots. + \item \texttt{density(self, categorical\_var, numerical\_var)}: displays the density of the numerical variable. + Each subpopulation should be represented by a separate curve on the graph. + \item \texttt{compare\_histograms(self, categorical\_var, numerical\_var)}: plots the numerical variable in a separate histogram for each category. + As an extra, you can use overlapping histograms with a color code. +\end{itemize} +BONUS: Your functions can also accept a list of numerical variables (instead of just one), and output a comparison plot for each variable in the list. diff --git a/module04/subject/assets/42ai_logo.pdf b/module04/subject/assets/42ai_logo.pdf index c915fc5c..1f5d3abb 100644 Binary files a/module04/subject/assets/42ai_logo.pdf and b/module04/subject/assets/42ai_logo.pdf differ diff --git a/module04/subject/en.acknowledgements.tex b/module04/subject/en.acknowledgements.tex new file mode 100644 index 00000000..ac0f036e --- /dev/null +++ b/module04/subject/en.acknowledgements.tex @@ -0,0 +1,38 @@ +\section*{Contact} +% --------------------------------- % +You can contact 42AI by email: \href{mailto:contact@42ai.fr}{contact@42ai.fr}\\ +\newline +Thank you for attending 42AI's Python Bootcamp module04 ! + +% ================================= % +\section*{Acknowledgements} +% --------------------------------- % +The Python bootcamp is the result of a collective work, for which we would like to thank: +\begin{itemize} + \item Maxime Choulika (cmaxime), + \item Pierre Peigné (ppeigne, pierre@42ai.fr), + \item Matthieu David (mdavid, matthieu@42ai.fr), + \item Quentin Feuillade--Montixi (qfeuilla, quentin@42ai.fr) + \item Mathieu Perez (maperez, mathieu.perez@42ai.fr) +\end{itemize} +who supervised the creation, the enhancement of the bootcamp and this present transcription. + +\begin{itemize} + \item Louis Develle (ldevelle, louis@42ai.fr) + \item Augustin Lopez (aulopez) + \item Luc Lenotre (llenotre) + \item Owen Roberts (oroberts) + \item Thomas Flahault (thflahau) + \item Amric Trudel (amric@42ai.fr) + \item Baptiste Lefeuvre (blefeuvr@student.42.fr) + \item Mathilde Boivin (mboivin@student.42.fr) + \item Tristan Duquesne (tduquesn@student.42.fr) +\end{itemize} +for your investment in the creation and development of these modules. + +\begin{itemize} + \item All prior participants who took a moment to provide their feedbacks, and help us improve these bootcamps ! +\end{itemize} + +\vfill +\doclicenseThis \ No newline at end of file diff --git a/module04/subject/en.instructions.tex b/module04/subject/en.instructions.tex new file mode 100644 index 00000000..168272a9 --- /dev/null +++ b/module04/subject/en.instructions.tex @@ -0,0 +1,36 @@ +\chapter{Common Instructions} +\begin{itemize} + \item The version of Python recommended to use is 3.7, you can + check the version of Python with the following command: \texttt{python -V} + + \item The norm: during this bootcamp, it is recommended to follow the + \href{https://www.python.org/dev/peps/pep-0008/}{PEP 8 standards}, though it is not mandatory. + You can install \href{https://pypi.org/project/pycodestyle}{pycodestyle} which + is a tool to check your Python code. + \item The function \texttt{eval} is never allowed. + \item The exercises are ordered from the easiest to the hardest. + \item Your exercises are going to be evaluated by someone else, + so make sure that your variable names and function names are appropriate and civil. + \item Your manual is the internet. + + \item If you are a student from 42, you can access our Discord server + on \href{https://discord.com/channels/887850395697807362/887850396314398720}{42 student's associations portal} and ask your + questions to your peers in the dedicated Bootcamp channel. + + \item You can learn more about 42 Artificial Intelligence by visiting \href{https://42-ai.github.io}{our website}. + + \item If you find any issue or mistake in the subject please create an issue on \href{https://github.com/42-AI/bootcamp_python/issues}{42AI repository on Github}. + + \item We encourage you to create test programs for your + project even though this work \textbf{won't have to be + submitted and won't be graded}. It will give you a chance + to easily test your work and your peers’ work. You will find + those tests especially useful during your defence. Indeed, + during defence, you are free to use your tests and/or the + tests of the peer you are evaluating. + + \item We are constantly looking to improve these bootcamps, and your feedbacks are essential for us to do so !\\ + You can tell us more about your experience with this module by filling \href{https://forms.gle/XCTac2mWnm7LAYhGA}{this form}.\\ + Thank you in advance and good luck for this bootcamp ! + +\end{itemize} \ No newline at end of file diff --git a/module04/subject/en.py_proj.tex b/module04/subject/en.py_proj.tex deleted file mode 100644 index ca41f240..00000000 --- a/module04/subject/en.py_proj.tex +++ /dev/null @@ -1,45 +0,0 @@ -%******************************************************************************% -% % -% Common Instructions % -% for Python Projects % -% % -%******************************************************************************% - -\chapter{Common Instructions} -\begin{itemize} - \item The version of Python recommended to use is 3.7, you can - check the version of Python with the following command: \texttt{python -V} - - \item The norm: during this bootcamp you will follow the - \href{https://www.python.org/dev/peps/pep-0008/}{PEP 8 standards}. - You can install \href{https://pypi.org/project/pycodestyle}{pycodestyle} which - is a tool to check your Python code. - - \item The function \texttt{eval} is never allowed. - - \item The exercises are ordered from the easiest to the hardest. - - \item Your exercises are going to be evaluated by someone else, - so make sure that your variable names and function names are appropriate and civil. - - \item Your manual is the internet. - - \item You can also ask questions in the \texttt{\#bootcamps} channel in the \href{https://42-ai.slack.com}{42AI} - or \href{42born2code.slack.com}{42born2code}. - - \item If you find any issue or mistakes in the subject please create an issue on \href{https://github.com/42-AI/bootcamp_python/issues}{42AI repository on Github}. - - \item We encourage you to create test programs for your - project even though this work \textbf{won't have to be - submitted and won't be graded}. It will give you a chance - to easily test your work and your peers’ work. You will find - those tests especially useful during your defence. Indeed, - during defence, you are free to use your tests and/or the - tests of the peer you are evaluating. - - \item Submit your work to your assigned git repository. Only the work in the - git repository will be graded. If Deepthought is assigned to grade your - work, it will be run after your peer-evaluations. - If an error happens in any section of your work during Deepthought's grading, - the evaluation will stop. -\end{itemize} \ No newline at end of file diff --git a/module04/subject/en.subject.pdf b/module04/subject/en.subject.pdf new file mode 100644 index 00000000..7fb0ef71 Binary files /dev/null and b/module04/subject/en.subject.pdf differ diff --git a/module04/subject/en.subject.pdf.version b/module04/subject/en.subject.pdf.version deleted file mode 100644 index 56a6051c..00000000 --- a/module04/subject/en.subject.pdf.version +++ /dev/null @@ -1 +0,0 @@ -1 \ No newline at end of file diff --git a/module04/subject/en.subject.tex b/module04/subject/en.subject.tex index d991b41e..4e708b0f 100644 --- a/module04/subject/en.subject.tex +++ b/module04/subject/en.subject.tex @@ -117,7 +117,7 @@ % =============================================================================% % ===================================== % -\title{Python \& ML - Module 04} +\title{Python Bootcamp - Module 04} \subtitle{Pandas} \author{ Maxime Choulika (cmaxime), Pierre Peigné (ppeigne), Matthieu David (mdavid) @@ -126,10 +126,10 @@ \summary { Today you will learn how to use a Python library that will allow you - to manipulate dataframes. + to manipulate gigantic amounts of data: Pandas. } \maketitle -\input{en.py_proj.tex} +\input{en.instructions.tex} \newpage \tableofcontents \startexercices @@ -146,555 +146,51 @@ % ============================================== % % ===========================(start ex 00) % -\chapter{Exercise 00} -\extitle{FileLoader} -\turnindir{ex00} -\exnumber{00} -\exfiles{FileLoader.py} -\exforbidden{None} -\makeheaderfilesforbidden - -% ================================== % -\section*{Objective} -% ---------------------------------- % -The goal of this exercise is to create a Fileloader class containing a -load and a display method. - -% ================================== % -\section*{Instructions} -% ---------------------------------- % -Write a class named \texttt{FileLoader} which implements the following methods: -\begin{itemize} - \item \texttt{load(path)}: takes as an argument the file path of the dataset to load, - displays a message specifying the dimensions of the dataset (e.g. 340 x 500) - and returns the dataset loaded as a pandas.DataFrame. - \item \texttt{display(df, n)}: takes a pandas.DataFrame and an integer as arguments, - displays the first n rows of the dataset if n is positive, or the last n rows if n is negative. -\end{itemize} - - -\noindent \texttt{FileLoader} object should not raise any exceptions (wrong path, file does not exist, parameters different than a string ...). -% ================================== % -\section*{Examples} -% ---------------------------------- % -\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} -from FileLoader import FileLoader -loader = FileLoader() -data = loader.load("../data/adult_data.csv") -# Output -Loading dataset of dimensions 32561 x 15 - - -loader.display(data, 12) -# Output -age workclass fnlwgt ... hours-per-week native-country salary -0 39 State-gov 77516 ... 40 United-States <=50K -1 50 Self-emp-not-inc 83311 ... 13 United-States <=50K -2 38 Private 215646 ... 40 United-States <=50K -3 53 Private 234721 ... 40 United-States <=50K -4 28 Private 338409 ... 40 Cuba <=50K -5 37 Private 284582 ... 40 United-States <=50K -6 49 Private 160187 ... 16 Jamaica <=50K -7 52 Self-emp-not-inc 209642 ... 45 United-States >50K -8 31 Private 45781 ... 50 United-States >50K -9 42 Private 159449 ... 40 United-States >50K -10 37 Private 280464 ... 80 United-States >50K -11 30 State-gov 141297 ... 40 India >50K - -[12 rows x 15 columns] -\end{minted} - -\hint{NB: Your terminal may display more columns if the window is wider.} - +\input{exercises/m04ex00.tex} % ===========================(fin ex 00) % % ============================================== % \newpage - % ============================================== % % ===========================(start ex 01) % -\chapter{Exercise 01} -\extitle{YoungestFellah} -\turnindir{ex01} -\exnumber{01} -\exfiles{FileLoader.py, YoungestFellah.py} -\exforbidden{None} -\makeheaderfilesforbidden - - -% ================================= % -\section*{Objective} -% --------------------------------- % -The goal of this exercise is to create a function that will return a -dictionary containing the age of the youngest woman and the youngest -man who took part in the Olympics a given year. - -% ================================= % -\section*{Instructions} -% --------------------------------- % -This exercise uses the following dataset: \texttt{athlete\_events.csv}. - -Write a function \texttt{youngestFellah} that takes two arguments: -\begin{itemize} - \item a pandas.DataFrame which contains the dataset - \item an Olympic year. -\end{itemize} - -The function returns a dictionary containing the age of the youngest -woman and man who took part in the Olympics on that year. -The name of the dictionary's keys is up to you, but it must be self-explanatory. - -% ================================= % -\section*{Examples} -% --------------------------------- % -\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} -from FileLoader import FileLoader -loader = FileLoader() -data = loader.load('../data/athlete_events.csv') -# Output -Loading dataset of dimensions 271116 x 15 - - -from YoungestFellah import youngestFellah -youngestFellah(data, 2004) -# Output -{'f': 13.0, 'm': 14.0} -\end{minted} - - +\input{exercises/m04ex01.tex} % ===========================(fin ex 01) % % ============================================== % - \newpage - % ============================================== % % ===========================(start ex 02) % -\chapter{Exercise 02} -\extitle{ProportionBySport} -\turnindir{ex02} -\exnumber{02} -\exfiles{FileLoader.py, ProportionBySport.py} -\exforbidden{None} -\makeheaderfilesforbidden - - -% ================================= % -\section*{Objective} -% --------------------------------- % -The goal of this exercise is to create a function displaying -the proportion of participants who played a given sport, among -the participants of a given genders. - -% ================================= % -\section*{Instructions} -% --------------------------------- % -This exercise uses the dataset \texttt{athlete\_events.csv}. - -Write a function \texttt{proportionBySport} that takes four arguments: -\begin{itemize} - \item a pandas.DataFrame of the dataset, - \item an olympic year, - \item a sport, - \item a gender. -\end{itemize} - -The function returns a float corresponding to the proportion (percentage) of participants -who played the given sport among the participants of the given gender. - -The function answers questions like the following : -"What was the percentage of female basketball players among all the female -participants of the 2016 Olympics?" - - -\hint{ -Here and further, if needed, drop duplicated sports people -to count only unique ones. Beware to call the dropping function -at the right moment and with the right parameters, in order not to omit any individuals. -} - -% ================================= % -\section*{Examples} -% --------------------------------- % -\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} -from FileLoader import FileLoader -loader = FileLoader() -data = loader.load('../data/athlete_events.csv') -# Output -Loading dataset of dimensions 271116 x 15 - - -from ProportionBySport import proportionBySport -proportionBySport(data, 2004, 'Tennis', 'F') -# Output -0.01935634328358209 -\end{minted} - -We assume that we are always using appropriate arguments as input, -and thus do not need to handle input errors. - +\input{exercises/m04ex02.tex} % ===========================(fin ex 02) % % ============================================== % - \newpage - % ============================================== % % ===========================(start ex 03) % -\chapter{Exercise 03} -\extitle{HowManyMedals} -\turnindir{ex03} -\exnumber{03} -\exfiles{FileLoader.py, HowManyMedals.py} -\exforbidden{None} -\makeheaderfilesforbidden - - -% ================================= % -\section*{Objective} -% --------------------------------- % -The goal of this exercise is to implement a function that will return -a dictionary of dictionaries giving the number and type of medals -for each year during which the participant won medals. - -% ================================= % -\section*{Instructions} -% --------------------------------- % -This exercise uses the following dataset: \texttt{athlete\_events.csv}. - - -Write a function \texttt{howManyMedals} that takes two arguments: -\begin{itemize} - \item a pandas.DataFrame which contains the dataset, - \item a participant name. -\end{itemize} - -The function returns a dictionary of dictionaries giving the number and type of medals -for each year during which the participant won medals. -The keys of the main dictionary are the Olympic games years. -In each year's dictionary, the keys are 'G', 'S', 'B' corresponding to the type of -medals won (gold, silver, bronze). The innermost values correspond to the number of -medals of a given type won for a given year. - -% ================================= % -\section*{Examples} -% --------------------------------- % -\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} -from FileLoader import FileLoader -loader = FileLoader() -data = loader.load('../data/athlete_events.csv') -# Output -Loading dataset of dimensions 271116 x 15 - - -from HowManyMedals import howManyMedals -howManyMedals(data, 'Kjetil Andr Aamodt') -# Output -{1992: {'G': 1, 'S': 0, 'B': 1}, - 1994: {'G': 0, 'S': 2, 'B': 1}, - 1998: {'G': 0, 'S': 0, 'B': 0}, - 2002: {'G': 2, 'S': 0, 'B': 0}, - 2006: {'G': 1, 'S': 0, 'B': 0}} -\end{minted} - +\input{exercises/m04ex03.tex} % ===========================(fin ex 03) % % ============================================== % - \newpage - % ============================================== % % ===========================(start ex 04) % -\chapter{Exercise 04} -\extitle{SpatioTemporalData} -\turnindir{ex04} -\exnumber{04} -\exfiles{FileLoader.py, SpatioTemporalData.py} -\exforbidden{None} -\makeheaderfilesforbidden - - -% ================================= % -\section*{Objective} -% --------------------------------- % -The goal of this exercise is to implement a class called \texttt{SpatioTemporalData} -that takes a dataset (pandas.DataFrame) as argument in its constructor -and implements two methods. - -% ================================= % -\section*{Instructions} -% --------------------------------- % -This exercise uses the dataset \texttt{athlete\_events.csv}. - - -Write a class called \texttt{SpatioTemporalData} that takes a dataset -(pandas.DataFrame) as argument in its constructor and implements the -following methods: -\begin{itemize} - \item \texttt{when(location)}: takes a location as an argument and returns - a list containing the years where games were held in the given location, - \item \texttt{where(date)}: takes a date as an argument and returns the location - where the Olympics took place in the given year. -\end{itemize} - -% ================================= % -\section*{Examples} -% --------------------------------- % -\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} -from FileLoader import FileLoader -loader = FileLoader() -data = loader.load('../data/athlete_events.csv') -# Output -Loading dataset of dimensions 271116 x 15 - - -from SpatioTemporalData import SpatioTemporalData -sp = SpatioTemporalData(data) -sp.where(1896) -# Output -['Athina'] - - -sp.where(2016) -# Output -['Rio de Janeiro'] - - -sp.when('Athina') -# Output -[2004, 1906, 1896] - - -sp.when('Paris') -# Output -[1900, 1924] -\end{minted} - - +\input{exercises/m04ex04.tex} % ===========================(fin ex 04) % % ============================================== % - \newpage - % ============================================== % % ===========================(start ex 05) % -\chapter{Exercise 05} -\extitle{HowManyMedalsByCountry} -\turnindir{ex05} -\exnumber{05} -\exfiles{FileLoader.py, HowManyMedalsByCountry.py} -\exforbidden{None} -\makeheaderfilesforbidden - - -% ================================= % -\section*{Objective} -% --------------------------------- % -The goal of this exercise is to write a function that returns a -dictionary of dictionaries giving the number and type of medal for -each competition where the country delegation earned medals. - -% ================================= % -\section*{Instructions} -% --------------------------------- % -This exercise uses the following dataset: \texttt{athlete\_events.csv} - -Write a function \texttt{howManyMedalsByCountry} that takes two arguments: -\begin{itemize} - \item a pandas.DataFrame which contains the dataset - \item a country name. -\end{itemize} - -The function returns a dictionary of dictionaries giving the number and -type of medal for each competition where the country delegation earned medals. -The keys of the main dictionary are the Olympic games' years. In each -year's dictionary, the key are 'G', 'S', 'B' corresponding to the -type of medals won. - -Duplicated medals per team games should be handled and not counted twice. - -% ================================= % -\section*{Examples} -% --------------------------------- % -\begin{minted}[bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize]{python} -from FileLoader import FileLoader -loader = FileLoader() -data = loader.load('../data/athlete_events.csv') -# Output -Loading dataset of dimensions 271116 x 15 - - -from HowManyMedalsByCountry import howManyMedalsByCountry -howManyMedalsByCountry(data, 'Martian Federation') -# Output -{2192: {'G': 17, 'S': 14, 'B': 23}, 2196: {'G': 8, 'S': 21, 'B': 19}, 2200: {'G': 26, 'S': 19, 'B': 7}} -\end{minted} - -You probably guessed by now that we gave up providing real examples... - -If you want real examples, you can easily look online. -Do beware that some medals might be awarded or removed years after the games -are over, for example if a previous medallist was found to have cheated -and is sanctioned. -The \texttt{athlete\_events.csv} dataset might not always take these posterior -changes into account. - +\input{exercises/m04ex05.tex} % ===========================(fin ex 05) % % ============================================== % - \newpage - % ============================================== % % ===========================(start ex 06) % -\chapter{Exercise 06} -\extitle{MyPlotLib} -\turnindir{ex06} -\exnumber{06} -\exfiles{MyPlotLib.py} -\exforbidden{None} -\makeheaderfilesforbidden - - -% ================================= % -\section*{Objective} -% --------------------------------- % -The goal the exercise is to introduce plotting methods among the different -libraries Pandas, Matplotlib, Seaborn or Scipy. - -% ================================= % -\section*{Instructions} -% --------------------------------- % -This exercise uses the following dataset: \texttt{athlete\_events.csv} - -Write a class called \texttt{MyPlotLib}. This class implements different plotting -methods, each of which take two arguments: -\begin{itemize} - \item a pandas.DataFrame which contains the dataset, - \item a list of feature names. -\end{itemize} - -\hint{ - What is a feature? https://towardsdatascience.com/feature-engineering-for-machine-learning-3a5e293a5114 -} - -\begin{itemize} - \item \texttt{histogram(data, features)}: plots one histogram for each numerical feature in the list, - \item \texttt{density(data, features)}: plots the density curve of each numerical feature in the list, - \item \texttt{pair\_plot(data, features)}: plots a matrix of subplots (also called scatter plot matrix). - On each subplot shows a scatter plot of one numerical variable against another one. - The main diagonal of this matrix shows simple histograms. - \item \texttt{box\_plot(data, features)}: displays a box plot for each numerical variable in the dataset. -\end{itemize} - -% ================================= % -\section*{Examples} -% --------------------------------- % - -\begin{figure}[h!] - \begin{minipage}[l]{0.49\linewidth} - \includegraphics[scale=0.39]{assets/ex06_histogram.png} - \caption{histogram} - \end{minipage} - \hfill - \begin{minipage}[c]{0.49\linewidth} - \includegraphics[scale=0.39]{assets/ex06_density.png} - \caption{density} - \end{minipage} - - \begin{minipage}[l]{0.49\linewidth} - \includegraphics[scale=0.39]{assets/ex06_pair_plot.png} - \caption{pair plot} - \end{minipage} - \hfill - \begin{minipage}[c]{0.49\linewidth} - \includegraphics[scale=0.39]{assets/ex06_box_plot.png} - \caption{box plot} - \end{minipage} -\end{figure} - - +\input{exercises/m04ex06.tex} % ===========================(fin ex 06) % % ============================================== % - \newpage - % ============================================== % % ===========================(start ex 07) % -\chapter{Exercise 07} -\extitle{Komparator} -\turnindir{ex07} -\exnumber{07} -\exfiles{Komparator.py, MyPlotLib.py (optional)} -\exforbidden{None} -\makeheaderfilesforbidden - - -% ================================= % -\section*{Objective} -% --------------------------------- % -The goal the exercise is to introduce plotting methods among the different -libraries Pandas, Matplotlib, Seaborn or Scipy. - -% ================================= % -\section*{Instructions} -% --------------------------------- % -This exercise uses the following dataset: \texttt{athlete\_events.csv}. - - -Write a class called \texttt{Komparator} whose constructor takes as an argument a pandas.DataFrame which contains the dataset. -The class must implement the following methods, which take as input two variable names: -\begin{itemize} - \item \texttt{compare\_box\_plots(categorical\_var, numerical\_var)}: displays a series of box plots - to compare how the distribution of the numerical variable changes if we only consider - the subpopulation which belongs to each category. - There should be as many box plots as categories. - For example, with Sex and Height, we would compare - the height distributions of men vs. women with two box plots. - \item \texttt{density(categorical\_var, numerical\_var)}: displays the density of the numerical variable. - Each subpopulation should be represented by a separate curve on the graph. - \item \texttt{compare\_histograms(categorical\_var, numerical\_var)}: plots the numerical variable in a separate histogram for each category. - As an extra, you can use overlapping histograms with a color code. -\end{itemize} - -BONUS: Your functions can also accept a list of numerical variables (instead of just one), and output a comparison plot for each variable in the list. - +\input{exercises/m04ex07.tex} % ===========================(fin ex 07) % % ============================================== % - \newpage - -% ================================= % -\section*{Contact} -% --------------------------------- % -You can contact 42AI association by email: contact@42ai.fr\\ -You can join the association on \href{https://join.slack.com/t/42-ai/shared_invite/zt-ebccw5r7-YPkDM6xOiYRPjqJXkrKgcA}{42AI slack} -and/or posutale to \href{https://forms.gle/VAFuREWaLmaqZw2D8}{one of the association teams}. - -% ================================= % -\section*{Acknowledgements} -% --------------------------------- % -The modules Python \& ML is the result of a collective work, we would like to thanks: -\begin{itemize} - \item Maxime Choulika (cmaxime), - \item Pierre Peigné (ppeigne), - \item Matthieu David (mdavid). -\end{itemize} -who supervised the creation, the enhancement and this present transcription. - -\begin{itemize} - \item Amric Trudel (amric@42ai.fr) - \item Baptiste Lefeuvre (blefeuvr@student.42.fr) - \item Mathilde Boivin (mboivin@student.42.fr) - \item Tristan Duquesne (tduquesn@student.42.fr) - \item Quentin Feuillade Montixi (qfeuilla@student.42.fr) -\end{itemize} -for your investment for the creation and development of these modules. - -\begin{itemize} - \item Barthélémy Leveque (bleveque@student.42.fr) - \item Remy Oster (roster@student.42.fr) - \item Quentin Bragard (qbragard@student.42.fr) - \item Marie Dufourq (madufour@student.42.fr) - \item Adrien Vardon (advardon@student.42.fr) -\end{itemize} -who betatest the first version of the modules of Machine Learning. -\vfill -\doclicenseThis - +\input{en.acknowledgements.tex} \end{document} \ No newline at end of file diff --git a/resources/.gitignore b/resources/.gitignore new file mode 100644 index 00000000..3f12d63b --- /dev/null +++ b/resources/.gitignore @@ -0,0 +1,10 @@ +.DS_Store +.aux +.log +.out +.pyg +.pyc +.toc +.o +*~ +#*# diff --git a/resources/latex/42-crea-en.cls b/resources/latex/42-crea-en.cls new file mode 100644 index 00000000..8f19197e --- /dev/null +++ b/resources/latex/42-crea-en.cls @@ -0,0 +1,808 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% 42.cls +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% Authors: +% - Maxime "zaz" Montinet +% - David "Thor" Giron +% +% Contributors: +% - Mathieu Mahé +% - Gaëtan JUVIN +% - Unknown for now +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +% This class provides a layout for teaching material at 42. +% +% This class is organized this way : +% +% I - Documentation +% 1. Incompatibilites +% II - General LaTeX boilerplate +% 1. Definition +% 2. Class options and parent class +% 3. Imports +% III - Lengths and color redefinitions +% 1. Lenghts +% 2. Colors +% 3. Hyperlinks +% 4. Listings +% 5. Page layout +% 6. Roman numerals for chapters +% IV - Frontpage customization +% 1. Custom fields +% 2. Redefinition of \maketitle +% 3. Exercice number +% V - Custom helper commands +% 1. Hint/warn +% 2. Lisibility helper +% 3. Exercise headers +% 4. Reproduction from man + +%% +%% I - Documentation +%% + +%% I.1 - Incompatibilities + +% Package ulem: +% The package ulem has a lot of oddities. Using it is not always a +% good idea. If you really want to do so, you should import it with +% the [normalem] option, as such : +% \usepackage[normalem]{ulem} +% Otherwise, it overrides \emph to underline the emphasized text. So +% far so good, but underlined text is typesetted in a box, which means +% that linebreaks don't happen automatically. Since \abstract (among +% others) uses \emph, the abstract is unreadable by default. +% Please read thoroughly ulem's doc before using it. +% See also: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=underline + +%% +%% II - General LaTeX boilerplate +%% + +%% II.1 - Definition + +\NeedsTeXFormat{LaTeX2e}[1995/12/01] +\ProvidesClass{42-en}[2014/08/22 v2.1 + LaTeX class for 42-themed documents] + +%% II.2 - Class options and parent class + +\newcommand{\summarytitle}{Summary}% + +\DeclareOption*{% + \PassOptionsToClass{\CurrentOption}{report} +} + +\ProcessOptions\relax +\LoadClass[a4paper,12pt,onecolumn]{report} + +%% II.3 - Imports + +\usepackage[top=1in,bottom=1in,left=1in,right=1in]{geometry} +\usepackage[pdftex]{graphicx} +\usepackage{url} +\usepackage{fancyhdr} +\usepackage{array} +\usepackage[table]{xcolor} +\usepackage[utf8]{inputenc} +\usepackage[T1]{fontenc} +\usepackage{lmodern} +\usepackage{listings} +\usepackage{tabularx} +\usepackage{textcomp} +\usepackage{color} +\usepackage[pdftex]{hyperref} +\usepackage{fancybox} +\usepackage{float} +\usepackage{atbeginend} % provided locally : atbeginend.sty +\usepackage{tocloft} % provided locally : tocloft.sty +\usepackage{multirow} % provided locally : multirow.sty +\usepackage[english]{babel} +\usepackage{minted} % provided locally : minted.sty +% Minted requires the Python "Pygments" librairy (http://pygments.org/). +% Pygments can be easily installed with the "easy_install" paquet manager +% from the "python-setuptools" paquet (sudo easy_install Pygments). +\usepackage{pifont,mdframed} +\usepackage{wallpaper} + +%% III - Lengths and color redefinitions + +%% III.1 - Lengths + +\AfterBegin{enumerate}{ + \itemsep10pt% +} +\AfterBegin{itemize}{ + \itemsep10pt% + \renewcommand{\labelitemi}{$\bullet$}% + \renewcommand{\labelitemii}{$\circ$}% +} + +\BeforeBegin{enumerate}{\vspace{15pt}} +\AfterEnd{enumerate}{\vspace{15pt}} + +\BeforeBegin{itemize}{\vspace{15pt}} +\AfterEnd{itemize}{\vspace{15pt}} + +\BeforeBegin{lstlisting}{\vspace{15pt}} +\AfterEnd{lstlisting}{\vspace{15pt}} + +\BeforeBegin{tabularx}{\vspace{15pt}} +\AfterEnd{tabularx}{\vspace{15pt}} + +%% III.2 - Colors + +\definecolor{nicergreen}{rgb}{0,0.502,0} +\definecolor{nicerblue}{rgb}{0,0.302,1} +\definecolor{nicerorange}{rgb}{1,0.502,0} +\definecolor{nicergrey}{rgb}{0.502,0.502,0.502} +\definecolor{nicerred}{rgb}{0.626,0,0} +\definecolor{hintbg}{rgb}{1.0,1.0,0.75} +\definecolor{warnbg}{rgb}{1.0,0.75,0.75} +\definecolor{infobg}{rgb}{0.75,0.75,1.0} +\definecolor{bibliotechbg}{RGB}{239,253,255} +\definecolor{lightgrey}{rgb}{0.95,0.95,0.95} +\definecolor{darkgrey}{rgb}{0.1,0.1,0.1} +\definecolor{assholeblack}{rgb}{0,0,0} + +%% III.3 - Hyperlinks + +\hypersetup +{ + colorlinks, +% citecolor=black, % +% filecolor=black, % + linkcolor=black, % black links + urlcolor=blue % blue URLs +} + +%% III.4 - Listings + +\lstset +{ + backgroundcolor=\color{gray!15}, + basicstyle=\small\ttfamily, + breaklines=true, + columns=fullflexible, + frame=lines, + tabsize=4, + numbers=none, %numbers=left, + numberstyle=\scriptsize\ttfamily, + numbersep=5pt, + showspaces=false, + showstringspaces=false, + showtabs=false, + breaklines=true, + upquote=true, + float +} + +%% III.5 - Page layout + +\makeatletter +\pagestyle{fancy} +\lhead{\@title} +\rhead{\@subtitle} +\cfoot{\thepage} +\makeatother + +%% III.6 - Roman chapter style + +% custom sections style + +\renewcommand{\thechapter}{\Roman{chapter}} + +% Using roman numerals makes the TOC section/subsection numbers +% overflow on the right. This adds some margin to avoid that kind of +% problems. (requires \usepackage{tocloft}) +\setlength{\cftchapnumwidth}{1.5cm} +\setlength{\cftsecnumwidth}{1.5cm} +\setlength{\cftsubsecnumwidth}{1.3cm} +\setlength{\cftsubsubsecnumwidth}{1.6cm} +\setlength{\cftaftertoctitleskip}{0.5cm} + +%% IV - Frontpage customization + +%% IV.1 - Custom fields +\makeatletter +\newcommand{\website}[1]{\def \@website {#1}} +\website{} + +\newcommand{\subtitle}[1]{\def \@subtitle {#1}} +\subtitle{} + +\newcommand{\schoollogo}[1]{\def \@schoollogo {#1}} +\schoollogo{42_logo.pdf} + +\newcommand{\summary}[1]{\def \@summary {#1}} +\summary{} + +\edef\@authors{} +\newcommand{\member}[2]{% + \protected@edef\@authors{\@authors #1 \protect\url{#2}\\} + \author{\@authors} +} +\author{} + +%% IV.2 - Redefine \maketitle + +\makeatletter +\def \maketitle { + \begin{titlepage} + \begin{center} + %\begin{figure}[t] + \includegraphics[height=8cm]{\@schoollogo} + %\end{figure} + \vskip 5em + {\huge \@title} + \vskip 2em + {\LARGE \@subtitle} + \vskip 4em + \end{center} + \begin{center} + \@author + \end{center} + \vskip 5em + \begin{center} + \emph{\summarytitle : \@summary} + \end{center} + \end{titlepage} +} +\makeatother + +\TileWallPaper{\paperwidth}{\paperheight}{back} +%% IV.3 - Exercice number + +\newcounter{exerciceCounter} +\newcommand*{\exercicenumber}{ + \ifnum\value{exerciceCounter}<10 0\fi + \arabic{exerciceCounter} +} + +\newcommand*{\startexercices}{ + \setcounter{exerciceCounter}{0} +} + +\newcommand*{\nextexercice}{ + \stepcounter{exerciceCounter} +} + +\newcounter{itemizeCounter} +\setcounter{itemizeCounter}{0} +\BeforeBegin{itemize}{ + \addtocounter{itemizeCounter}{1} +} + +\AfterEnd{itemize}{ + \addtocounter{itemizeCounter}{-1} + \ifnum\value{itemizeCounter} = 0 + \stepcounter{exerciceCounter} + \fi +} + +%% V - Custom helper commands + +%% V.1 - Hint/Warn + +% hint command + +\newcommand{\kbox}[3] +{ + \vskip 15pt + \noindent + \colorbox{#1} + { + \begin{tabular*}{0.97\textwidth}{m{4em}m{0.8\textwidth}} + \includegraphics[width=4em]{#2} + & {\ttfamily\footnotesize #3}\\ + \end{tabular*} + } + \vskip 15pt +} + +\newcommand{\hint}[1]{\kbox{hintbg}{helphint.pdf}{#1}} +\newcommand{\warn}[1]{\kbox{warnbg}{warn.pdf}{#1}} +\newcommand{\info}[1]{\kbox{infobg}{info.pdf}{#1}} + +%% V.2 Lisibility helper + +\makeatletter +\newcommand{\mso}[1]{ + \ttfamily #1 \normalfont +} + +%% V.3 Exercise headers + +\makeatletter +\newcommand{\turnindir}[1]{\def \@turnindir {#1}} +\newcommand{\daypiscine}[1]{\def \@daypiscine {#1}} +\newcommand{\extitle}[1]{\def \@extitle {#1}} +\newcommand{\exnumber}[1]{\def \@exnumber {#1}} +\newcommand{\exscore}[1]{\def \@exscore {#1}} +\newcommand{\exflags}[1][-W -Wall -Werror]{\def \@exflags {#1}} +\newcommand{\excompil}[1][gcc]{\def \@excompil {#1}} +\newcommand{\exrules}[1][n/a]{\def \@exrules {#1}} +\newcommand{\exfiles}[1]{\def \@exfiles {#1}} +\newcommand{\exnotes}[1][n/a]{\def \@exnotes {#1}} +\newcommand{\exauthorize}[1]{\def \@exauthorize {#1}} +\newcommand{\exforbidden}[1]{\def \@exforbidden {#1}} +\newcommand{\exdocres}[1]{\def \@exdocres {#1}} +\newcommand{\exdocsize}[1]{\def \@exdocsize {#1}} +\newcommand{\excolormode}[1]{\def \@excolormode {#1}} +\newcommand{\exmake}[1][No]{\def \@exmake {#1}} + + +% Default values +\turnindir{} +\daypiscine{} +\extitle{} +\exnumber{} +\exscore{} +\exflags{} +\excompil{} +\exrules{} +\exfiles{} +\exnotes{} +\exauthorize{None} +\exforbidden{None} +\exmake{} + +%Header pour exercices sans rien a "rendre" +\newcommand{\makeheaderbasic} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercise : \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Notes : \ttfamily \@exnotes } + \\ \hline +\end{tabularx} +\exnotes +\exrules +\exmake +\exauthorize{None} +\exforbidden{None} +\extitle{} +\exnumber{} +} + +%Header pour exercices sans code mais fichiers a rendre +\newcommand{\makeheaderfiles} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercise \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Turn-in directory : \ttfamily + $ex\@exnumber/$ } + \\ \hline + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Files to turn in : \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Allowed functions : \ttfamily \@exauthorize } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Notes : \ttfamily \@exnotes } + \\ \hline +\end{tabularx} +\exnotes +\exrules +\exmake +\exauthorize{None} +\exforbidden{None} +\extitle{} +\exnumber{} +} + +%Header pour exercices sans code mais fichiers a rendre +\newcommand{\makeheaderfilesforbidden} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercise \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Turn-in directory : \ttfamily + $ex\@exnumber/$ } + \\ \hline + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Files to turn in : \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Forbidden functions : \ttfamily \@exforbidden } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Remarks : \ttfamily \@exnotes } + \\ \hline +\end{tabularx} +\exnotes +\exrules +\exmake +\exauthorize{None} +\exforbidden{None} +\extitle{} +\exnumber{} +} + +%Header pour exercices de code +\newcommand{\makeheadercode} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercise \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} + %% {\scriptsize Score : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Turn-in directory: \ttfamily + $ex\@exnumber/$ } + \\ \hline + + \multicolumn{2}{|>{\raggedright}m{7.5cm}} + {\small Compiler: \ttfamily \@excompil } & + \multicolumn{2}{|>{\raggedright}m{7.5cm}|} + {\small Compilation flags: + \ttfamily \@exflags } + \\ \hline + + \multicolumn{2}{|>{\raggedright}m{7.52cm}} + {\small Makefile: \ttfamily{\@exmake}} & + \multicolumn{2}{|>{\raggedright}m{7.5cm}|} + {Makefile rules: \ttfamily \@exrules } \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Files to turn in: \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Notes : \ttfamily \@exnotes } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Forbidden fonctions: \ttfamily \@exforbidden } + \\ \hline +\end{tabularx} +\exnotes +\exrules +\exmake +\exforbidden{None} +\exauthorize{None} +\extitle{} +\exnumber{} +} + +%Header pour exercices sur Photoshop + +\newcommand{\makephotoshopheader} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercice : \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Turn-in directory : \ttfamily + $ex\@exnumber/$ } + \\ \hline + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Document size : \ttfamily \@exdocsize } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Document resolution : \ttfamily \@exdocres } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Color mode : \ttfamily \@excolormode } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Forbidden functions : \ttfamily \@exforbidden } + \\ \hline + +\end{tabularx} +\exnotes +\exrules +\exmake +\exdocres{300dpi} +\exdocsize{1980x1080px} +\excolormode{RGB} +\exforbidden{Aucune} +\extitle{} +\exnumber{} +} + + +\newcommand{\exmandatory}{Mandatory exercise} +\newcommand{\exretrovalid}{Retrovalidated exercise} +\newcommand{\exoptional}{Optional exercise} + +\newcommand{\exercice}{Exercise} + +%% V.4 Reproduction from man +\newcommand{\reproductionfromman}[1]{Reproduce the behavior of the function \texttt{#1} (man #1).} + +%% VI - Syntactic highlights + + +%% Styles: +%% ~~~~~~~ +%% * monokai: +%% This style mimics the Monokai color scheme. +%% * manni: +%% A colorful style, inspired by the terminal highlighting style. +%% * rrt: +%% Minimalistic ``rrt'' theme, based on Zap and Emacs defaults. +%% * perldoc: +%% Style similar to the style used in the perldoc code blocks. +%% * borland: +%% Style similar to the style used in the borland IDEs. +%% * colorful: +%% A colorful style, inspired by CodeRay. +%% * default: +%% The default style (inspired by Emacs 22). +%% * murphy: +%% Murphy's style from CodeRay. +%% * vs: +%% +%% * trac: +%% Port of the default trac highlighter design. +%% * tango: +%% The Crunchy default Style inspired from the color palette from the Tango Icon Theme Guidelines. +%% * fruity: +%% Pygments version of the ``native'' vim theme. +%% * autumn: +%% A colorful style, inspired by the terminal highlighting style. +%% * bw: +%% +%% * emacs: +%% The default style (inspired by Emacs 22). +%% * vim: +%% Styles somewhat like vim 7.0 +%% * pastie: +%% Style similar to the pastie default style. +%% * friendly: +%% A modern style based on the VIM pyte theme. +%% * native: +%% Pygments version of the ``native'' vim theme. + + + +%\usemintedstyle{monokai} +%\usemintedstyle{manni} +%\usemintedstyle{rrt} +%\usemintedstyle{perldoc} +%\usemintedstyle{borland} +%\usemintedstyle{colorful} +%\usemintedstyle{default} +%\usemintedstyle{murphy} +%\usemintedstyle{vs} +%\usemintedstyle{trac} +%\usemintedstyle{tango} +%\usemintedstyle{fruity} +%\usemintedstyle{autumn} +%\usemintedstyle{bw} +%\usemintedstyle{emacs} +%\usemintedstyle{vim} +%\usemintedstyle{pastie} +%\usemintedstyle{friendly} +%\usemintedstyle{native} + +\makeatletter +\newenvironment{42ccode}{% + \VerbatimEnvironment + \usemintedstyle{emacs} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{c} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42phpcode}{% + \VerbatimEnvironment + \usemintedstyle{emacs} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{html+php} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42yamlcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{yaml} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\definecolor{darcula-back}{RGB}{35, 37, 37} + +\makeatletter +\newenvironment{42javacode}{% + \VerbatimEnvironment + \usemintedstyle{monokai} + \minted@resetoptions + \definecolor{dark}{RGB}{35, 37, 37} + \setkeys{minted@opt}{bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{java} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42xmlcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{xml} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42cppcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{c++} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + + +\makeatletter +\newenvironment{42ocamlcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{ocaml} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + + +\makeatletter +\newenvironment{42asmcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{nasm} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\lstnewenvironment{42console} { + \lstset { + basicstyle=\color{lightgrey}\scriptsize\ttfamily, + backgroundcolor=\color{assholeblack}, + breaklines=true, + numberstyle=\scriptsize, + columns=flexible, + keepspaces=true, + } +}{} + +\newenvironment{42warning} + {\vspace*{1\baselineskip} + \par\begin{mdframed}[linewidth=2pt,linecolor=red]% + \begin{list}{}{\leftmargin=1cm + \labelwidth=\leftmargin}\item[\Large\ding{43}]} + {\end{list}\end{mdframed}\par \vspace*{1\baselineskip}} diff --git a/resources/latex/42-crea-fr.cls b/resources/latex/42-crea-fr.cls new file mode 100644 index 00000000..6d833764 --- /dev/null +++ b/resources/latex/42-crea-fr.cls @@ -0,0 +1,822 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% 42.cls +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% Authors: +% - Maxime "zaz" Montinet +% - David "Thor" Giron +% +% Contributors: +% - Mathieu Mahé +% - Gaëtan JUVIN +% - Franck 'coton' LOURME +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +% This class provides a layout for teaching material at 42. +% +% This class is organized this way : +% +% I - Documentation +% 1. Incompatibilites +% II - General LaTeX boilerplate +% 1. Definition +% 2. Class options and parent class +% 3. Imports +% III - Lengths and color redefinitions +% 1. Lenghts +% 2. Colors +% 3. Hyperlinks +% 4. Listings +% 5. Page layout +% 6. Roman numerals for chapters +% IV - Frontpage customization +% 1. Custom fields +% 2. Redefinition of \maketitle +% 3. Exercice number +% V - Custom helper commands +% 1. Hint/warn +% 2. Lisibility helper +% 3. Exercise headers +% 4. Reproduction from man + +%% +%% I - Documentation +%% + +%% I.1 - Incompatibilities + +% Package ulem: +% The package ulem has a lot of oddities. Using it is not always a +% good idea. If you really want to do so, you should import it with +% the [normalem] option, as such : +% \usepackage[normalem]{ulem} +% Otherwise, it overrides \emph to underline the emphasized text. So +% far so good, but underlined text is typesetted in a box, which means +% that linebreaks don't happen automatically. Since \abstract (among +% others) uses \emph, the abstract is unreadable by default. +% Please read thoroughly ulem's doc before using it. +% See also: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=underline + +%% +%% II - General LaTeX boilerplate +%% + +%% II.1 - Definition + +\NeedsTeXFormat{LaTeX2e}[1995/12/01] +\ProvidesClass{42-crea-fr}[2010/07/15 v2.0 + LaTeX class for 42-themed documents related to Creative Cursus] + +%% II.2 - Class options and parent class + +\newcommand{\summarytitle}{R\'esum\'e}% + +\DeclareOption*{% + \PassOptionsToClass{\CurrentOption}{report} +} + +\ProcessOptions\relax +\LoadClass[a4paper,12pt,onecolumn]{report} + +%% II.3 - Imports + +\usepackage[top=1in,bottom=1in,left=1in,right=1in]{geometry} +\usepackage[pdftex]{graphicx} +\usepackage{url} +\usepackage{fancyhdr} +\usepackage{array} +\usepackage[table]{xcolor} +\usepackage[utf8]{inputenc} +\usepackage[T1]{fontenc} +\usepackage{lmodern} +\usepackage{listings} +\usepackage{tabularx} +\usepackage{textcomp} +\usepackage{color} +\usepackage[pdftex]{hyperref} +\usepackage{fancybox} +\usepackage{float} +\usepackage{atbeginend} % provided locally : atbeginend.sty +\usepackage{tocloft} % provided locally : tocloft.sty +\usepackage{multirow} % provided locally : multirow.sty +\usepackage[french]{babel} +\usepackage{minted} % provided locally : minted.sty +% Minted requires the Python "Pygments" librairy (http://pygments.org/). +% Pygments can be easily installed with the "easy_install" paquet manager +% from the "python-setuptools" paquet (sudo easy_install Pygments). +\usepackage{pifont,mdframed} +%% III - Lengths and color redefinitions + +%% III.1 - Lengths + +\AfterBegin{enumerate}{ + \itemsep10pt% +} +\AfterBegin{itemize}{ + \itemsep10pt% + \renewcommand{\labelitemi}{$\bullet$}% + \renewcommand{\labelitemii}{$\circ$}% +} + +\BeforeBegin{enumerate}{\vspace{15pt}} +\AfterEnd{enumerate}{\vspace{15pt}} + +\BeforeBegin{itemize}{\vspace{15pt}} +\AfterEnd{itemize}{\vspace{15pt}} + +\BeforeBegin{lstlisting}{\vspace{15pt}} +\AfterEnd{lstlisting}{\vspace{15pt}} + +\BeforeBegin{tabularx}{\vspace{15pt}} +\AfterEnd{tabularx}{\vspace{15pt}} + +%% III.2 - Colors + +\definecolor{nicergreen}{rgb}{0,0.502,0} +\definecolor{nicerblue}{rgb}{0,0.302,1} +\definecolor{nicerorange}{rgb}{1,0.502,0} +\definecolor{nicergrey}{rgb}{0.502,0.502,0.502} +\definecolor{nicerred}{rgb}{0.626,0,0} +\definecolor{hintbg}{rgb}{1.0,1.0,0.75} +\definecolor{warnbg}{rgb}{1.0,0.75,0.75} +\definecolor{infobg}{rgb}{0.75,0.75,1.0} +\definecolor{bibliotechbg}{RGB}{239,253,255} +\definecolor{lightgrey}{rgb}{0.95,0.95,0.95} +\definecolor{darkgrey}{rgb}{0.1,0.1,0.1} +\definecolor{assholeblack}{rgb}{0,0,0} + +%% III.3 - Hyperlinks + +\hypersetup +{ + colorlinks, +% citecolor=black, % +% filecolor=black, % + linkcolor=black, % black links + urlcolor=blue % blue URLs +} + +%% III.4 - Listings + +\lstset +{ + backgroundcolor=\color{gray!15}, + basicstyle=\small\ttfamily, + breaklines=true, + columns=fullflexible, + frame=lines, + tabsize=4, + numbers=none, %numbers=left, + numberstyle=\scriptsize\ttfamily, + numbersep=5pt, + showspaces=false, + showstringspaces=false, + showtabs=false, + breaklines=true, + upquote=true, + float +} + +%% III.5 - Page layout + +\makeatletter +\pagestyle{fancy} +\lhead{\@title} +\rhead{\@subtitle} +\cfoot{\thepage} +\makeatother + +%% III.6 - Roman chapter style + +% custom sections style + +\renewcommand{\thechapter}{\Roman{chapter}} + +% Using roman numerals makes the TOC section/subsection numbers +% overflow on the right. This adds some margin to avoid that kind of +% problems. (requires \usepackage{tocloft}) +\setlength{\cftchapnumwidth}{1.5cm} +\setlength{\cftsecnumwidth}{1.5cm} +\setlength{\cftsubsecnumwidth}{1.3cm} +\setlength{\cftsubsubsecnumwidth}{1.6cm} +\setlength{\cftaftertoctitleskip}{0.5cm} + +%% IV - Frontpage customization + +%% IV.1 - Custom fields +\makeatletter +\newcommand{\website}[1]{\def \@website {#1}} +\website{} + +\newcommand{\subtitle}[1]{\def \@subtitle {#1}} +\subtitle{} + +\newcommand{\schoollogo}[1]{\def \@schoollogo {#1}} +\schoollogo{42_logo.pdf} + +\newcommand{\summary}[1]{\def \@summary {#1}} +\summary{} + +\edef\@authors{} +\newcommand{\member}[2]{% + \protected@edef\@authors{\@authors #1 \protect\url{#2}\\} + \author{\@authors} +} +\author{} + +%% IV.2 - Redefine \maketitle + +\makeatletter +\def \maketitle { + \begin{titlepage} + \begin{center} + %\begin{figure}[t] + \includegraphics[height=8cm]{\@schoollogo} + %\end{figure} + \vskip 5em + {\huge \@title} + \vskip 2em + {\LARGE \@subtitle} + \vskip 4em + \end{center} + \begin{center} + \@author + \end{center} + \vskip 5em + \begin{center} + \emph{\summarytitle : \@summary} + \end{center} + \end{titlepage} +} +\makeatother + +\fancyput(-2.54cm,-27.16cm){\includegraphics[width=21cm,height=29.7cm]{back}} + +%% IV.3 - Exercice number + +\newcounter{exerciceCounter} +\newcommand*{\exercicenumber}{ + \ifnum\value{exerciceCounter}<10 0\fi + \arabic{exerciceCounter} +} + +\newcommand*{\startexercices}{ + \setcounter{exerciceCounter}{0} +} + +\newcommand*{\nextexercice}{ + \stepcounter{exerciceCounter} +} + +\newcounter{itemizeCounter} +\setcounter{itemizeCounter}{0} +\BeforeBegin{itemize}{ + \addtocounter{itemizeCounter}{1} +} + +\AfterEnd{itemize}{ + \addtocounter{itemizeCounter}{-1} + \ifnum\value{itemizeCounter} = 0 + \stepcounter{exerciceCounter} + \fi +} + +%% V - Custom helper commands + +%% V.1 - Hint/Warn + +% hint command + +\newcommand{\kbox}[3] +{ + \vskip 15pt + \noindent + \colorbox{#1} + { + \begin{tabular*}{0.97\textwidth}{m{4em}m{0.8\textwidth}} + \includegraphics[width=4em]{#2} + & {\ttfamily\footnotesize #3}\\ + \end{tabular*} + } + \vskip 15pt +} + +\newcommand{\hint}[1]{\kbox{hintbg}{helphint.pdf}{#1}} +\newcommand{\warn}[1]{\kbox{warnbg}{warn.pdf}{#1}} +\newcommand{\info}[1]{\kbox{infobg}{info.pdf}{#1}} + +%% V.2 Lisibility helper + +\makeatletter +\newcommand{\mso}[1]{ + \ttfamily #1 \normalfont +} + +%% V.3 Exercise headers + +\makeatletter +\newcommand{\turnindir}[1]{\def \@turnindir {#1}} +\newcommand{\daypiscine}[1]{\def \@daypiscine {#1}} +\newcommand{\extitle}[1]{\def \@extitle {#1}} +\newcommand{\exnumber}[1]{\def \@exnumber {#1}} +\newcommand{\exscore}[1]{\def \@exscore {#1}} +\newcommand{\exflags}[1][-W -Wall -Werror]{\def \@exflags {#1}} +\newcommand{\excompil}[1][gcc]{\def \@excompil {#1}} +\newcommand{\exrules}[1][n/a]{\def \@exrules {#1}} +\newcommand{\exfiles}[1]{\def \@exfiles {#1}} +\newcommand{\exnotes}[1][n/a]{\def \@exnotes {#1}} +\newcommand{\exauthorize}[1]{\def \@exauthorize {#1}} +\newcommand{\exforbidden}[1]{\def \@exforbidden {#1}} +\newcommand{\exdocres}[1]{\def \@exdocres {#1}} +\newcommand{\exdocsize}[1]{\def \@exdocsize {#1}} +\newcommand{\excolormode}[1]{\def \@excolormode {#1}} +\newcommand{\exmake}[1][Non]{\def \@exmake {#1}} + +% Default values +\turnindir{} +\daypiscine{} +\extitle{} +\exnumber{} +\exscore{} +\exflags{} +\excompil{} +\exrules{} +\exfiles{} +\exnotes{} +\exauthorize{Aucune} +\exforbidden{Aucune} +\exmake{} + +%Header pour exercices sans rien a "rendre" +\newcommand{\makeheaderbasic} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercice : \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Remarques : \ttfamily \@exnotes } + \\ \hline +\end{tabularx} +\exnotes +\exrules +\exmake +%\exauthorize +\exforbidden{Aucune} +\extitle{} +\exnumber{} +} + +%Header pour exercices sans code mais fichiers a rendre +\newcommand{\makeheaderfiles} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercice : \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Dossier de rendu : \ttfamily + $ex\@exnumber/$ } + \\ \hline + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Fichiers \`a rendre : \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Fonctions Autoris\'ees : \ttfamily \@exauthorize } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Remarques : \ttfamily \@exnotes } + \\ \hline +\end{tabularx} +\exnotes +\exrules +\exmake +\exauthorize{Aucune} +\exforbidden{Aucune} +\extitle{} +\exnumber{} +} + +%Header pour exercices sans dossier de rendu +\newcommand{\makeheaderfilesnodirectory} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercice : \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Fichiers \`a rendre : \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Fonctions Autoris\'ees : \ttfamily \@exauthorize } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Remarques : \ttfamily \@exnotes } + \\ \hline +\end{tabularx} +\exnotes +\exrules +\exmake +\exauthorize{Aucune} +\exforbidden{Aucune} +\extitle{} +\exnumber{} +} + +%Header pour exercices sans code mais fichiers a rendre +\newcommand{\makeheaderfilesforbidden} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercice : \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Dossier de rendu : \ttfamily + $ex\@exnumber/$ } + \\ \hline + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Fichiers \`a rendre : \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Fonctions interdites : \ttfamily \@exforbidden } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Remarques : \ttfamily \@exnotes } + \\ \hline +\end{tabularx} +\exnotes +\exrules +\exmake +\exauthorize{Aucune} +\exforbidden{Aucune} +\extitle{} +\exnumber{} +} + +%Header pour exercices de code +\newcommand{\makeheadercode} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercice : \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} + %% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Dossier de rendu: \ttfamily + $ex\@exnumber/$ } + \\ \hline + + \multicolumn{2}{|>{\raggedright}m{7.5cm}} + {\small Compilateur : \ttfamily \@excompil } & + \multicolumn{2}{|>{\raggedright}m{7.5cm}|} + {\small Flags de compilation: + \ttfamily \@exflags } + \\ \hline + + \multicolumn{2}{|>{\raggedright}m{7.52cm}} + {\small Makefile : \ttfamily{\@exmake}} & + \multicolumn{2}{|>{\raggedright}m{7.5cm}|} + {R\`{e}gles : \ttfamily \@exrules } \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Fichiers \`a rendre : \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Remarques : \ttfamily \@exnotes } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Fonctions Interdites : \ttfamily \@exforbidden } + \\ \hline +\end{tabularx} +\exnotes +\exrules +\exmake +\exforbidden{Aucune} +\extitle{} +\exnumber{} +} + +\newcommand{\exmandatory}{Exercice obligatoire} +\newcommand{\exretrovalid}{Exercice rétrovalidable} +\newcommand{\exoptional}{Exercice bonus} + +\newcommand{\exercice}{Exercice} + +%Header pour exercices sur Photoshop + +\newcommand{\makephotoshopheader} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercice : \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Dossier de rendu : \ttfamily + $ex\@exnumber/$ } + \\ \hline + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Taille du document : \ttfamily \@exdocsize } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Resolution du document : \ttfamily \@exdocres } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Mode colorimétrique : \ttfamily \@excolormode } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Fonctions interdites : \ttfamily \@exforbidden } + \\ \hline + +\end{tabularx} +\exnotes +\exrules +\exmake +\exdocres{300dpi} +\exdocsize{1980x1080px} +\excolormode{RGB} +\exforbidden{Aucune} +\extitle{} +\exnumber{} +} + +%% V.4 Reproduction from man +\newcommand{\reproductionfromman}[1]{Reproduire \`a l'identique le fonctionnement de la fonction \texttt{#1} (man #1).} + +%% VI - Syntactic highlights + + +%% Styles: +%% ~~~~~~~ +%% * monokai: +%% This style mimics the Monokai color scheme. +%% * manni: +%% A colorful style, inspired by the terminal highlighting style. +%% * rrt: +%% Minimalistic ``rrt'' theme, based on Zap and Emacs defaults. +%% * perldoc: +%% Style similar to the style used in the perldoc code blocks. +%% * borland: +%% Style similar to the style used in the borland IDEs. +%% * colorful: +%% A colorful style, inspired by CodeRay. +%% * default: +%% The default style (inspired by Emacs 22). +%% * murphy: +%% Murphy's style from CodeRay. +%% * vs: +%% +%% * trac: +%% Port of the default trac highlighter design. +%% * tango: +%% The Crunchy default Style inspired from the color palette from the Tango Icon Theme Guidelines. +%% * fruity: +%% Pygments version of the ``native'' vim theme. +%% * autumn: +%% A colorful style, inspired by the terminal highlighting style. +%% * bw: +%% +%% * emacs: +%% The default style (inspired by Emacs 22). +%% * vim: +%% Styles somewhat like vim 7.0 +%% * pastie: +%% Style similar to the pastie default style. +%% * friendly: +%% A modern style based on the VIM pyte theme. +%% * native: +%% Pygments version of the ``native'' vim theme. + + + +%\usemintedstyle{monokai} +%\usemintedstyle{manni} +%\usemintedstyle{rrt} +%\usemintedstyle{perldoc} +%\usemintedstyle{borland} +%\usemintedstyle{colorful} +%\usemintedstyle{default} +%\usemintedstyle{murphy} +%\usemintedstyle{vs} +%\usemintedstyle{trac} +%\usemintedstyle{tango} +%\usemintedstyle{fruity} +%\usemintedstyle{autumn} +%\usemintedstyle{bw} +%\usemintedstyle{emacs} +%\usemintedstyle{vim} +%\usemintedstyle{pastie} +%\usemintedstyle{friendly} +%\usemintedstyle{native} + +\makeatletter +\newenvironment{42ccode}{% + \VerbatimEnvironment + \usemintedstyle{emacs} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{c} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42phpcode}{% + \VerbatimEnvironment + \usemintedstyle{emacs} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{html+php} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42jscode}{% + \VerbatimEnvironment + \usemintedstyle{emacs} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{js} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42yamlcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{yaml} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42cppcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{c++} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + + +\makeatletter +\newenvironment{42ocamlcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{ocaml} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + + +\makeatletter +\newenvironment{42asmcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{nasm} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\lstnewenvironment{42console} { + \lstset { + extendedchars=true, + literate={✓}{{\checkmark}}1, + basicstyle=\color{lightgrey}\scriptsize\ttfamily, + backgroundcolor=\color{assholeblack}, + breaklines=true, + numberstyle=\scriptsize, + columns=flexible, + keepspaces=true, + } +}{} + +\newenvironment{42warning} + {\vspace*{1\baselineskip} + \par\begin{mdframed}[linewidth=2pt,linecolor=red]% + \begin{list}{}{\leftmargin=1cm + \labelwidth=\leftmargin}\item[\Large\ding{43}]} + {\end{list}\end{mdframed}\par \vspace*{1\baselineskip}} diff --git a/resources/latex/42-en.cls b/resources/latex/42-en.cls new file mode 100644 index 00000000..4f9ef93e --- /dev/null +++ b/resources/latex/42-en.cls @@ -0,0 +1,895 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% 42.cls +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% Authors: +% - Maxime "zaz" Montinet +% - David "Thor" Giron +% +% Contributors: +% - Mathieu Mahé +% - Gaëtan JUVIN +% - Unknown for now +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +% This class provides a layout for teaching material at 42. +% +% This class is organized this way : +% +% I - Documentation +% 1. Incompatibilites +% II - General LaTeX boilerplate +% 1. Definition +% 2. Class options and parent class +% 3. Imports +% III - Lengths and color redefinitions +% 1. Lenghts +% 2. Colors +% 3. Hyperlinks +% 4. Listings +% 5. Page layout +% 6. Roman numerals for chapters +% IV - Frontpage customization +% 1. Custom fields +% 2. Redefinition of \maketitle +% 3. Exercice number +% V - Custom helper commands +% 1. Hint/warn +% 2. Lisibility helper +% 3. Exercise headers +% 4. Reproduction from man + +%% +%% I - Documentation +%% + +%% I.1 - Incompatibilities + +% Package ulem: +% The package ulem has a lot of oddities. Using it is not always a +% good idea. If you really want to do so, you should import it with +% the [normalem] option, as such : +% \usepackage[normalem]{ulem} +% Otherwise, it overrides \emph to underline the emphasized text. So +% far so good, but underlined text is typesetted in a box, which means +% that linebreaks don't happen automatically. Since \abstract (among +% others) uses \emph, the abstract is unreadable by default. +% Please read thoroughly ulem's doc before using it. +% See also: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=underline + +%% +%% II - General LaTeX boilerplate +%% + +%% II.1 - Definition + +\NeedsTeXFormat{LaTeX2e}[1995/12/01] +\ProvidesClass{42-en}[2014/08/22 v2.1 + LaTeX class for 42-themed documents] + +%% II.2 - Class options and parent class + +\newcommand{\summarytitle}{Summary}% + +\newcommand{\versiontitle}{Version}% + +\DeclareOption*{% + \PassOptionsToClass{\CurrentOption}{report} +} + +\ProcessOptions\relax +\LoadClass[a4paper,12pt,onecolumn]{report} + +%% II.3 - Imports + +\usepackage[top=1in,bottom=1in,left=1in,right=1in]{geometry} +\usepackage[pdftex]{graphicx} +\usepackage{url} +\usepackage{fancyhdr} +\usepackage{array} +\usepackage[table]{xcolor} +\usepackage[utf8]{inputenc} +\usepackage[T1]{fontenc} +\usepackage{lmodern} +\usepackage{listings} +\usepackage{tabularx} +\usepackage{textcomp} +\usepackage{color} +\usepackage[pdftex]{hyperref} +\usepackage{fancybox} +\usepackage{float} +\usepackage{atbeginend} % provided locally : atbeginend.sty +\usepackage{tocloft} % provided locally : tocloft.sty +\usepackage{multirow} % provided locally : multirow.sty +\usepackage[english]{babel} +\usepackage{minted} % provided locally : minted.sty +% Minted requires the Python "Pygments" librairy (http://pygments.org/). +% Pygments can be easily installed with the "easy_install" paquet manager +% from the "python-setuptools" paquet (sudo easy_install Pygments). +\usepackage{pifont,mdframed} +\usepackage{wallpaper} + +%% III - Lengths and color redefinitions + +%% III.1 - Lengths + +\AfterBegin{enumerate}{ + \itemsep10pt% +} +\AfterBegin{itemize}{ + \itemsep5pt% + \renewcommand{\labelitemi}{$\bullet$}% + \renewcommand{\labelitemii}{$\circ$}% +} + +\BeforeBegin{enumerate}{\vspace{15pt}} +\AfterEnd{enumerate}{\vspace{15pt}} + +\BeforeBegin{itemize}{\vspace{15pt}} +\AfterEnd{itemize}{\vspace{15pt}} + +\BeforeBegin{lstlisting}{\vspace{15pt}} +\AfterEnd{lstlisting}{\vspace{15pt}} + +\BeforeBegin{tabularx}{\vspace{15pt}} +\AfterEnd{tabularx}{\vspace{15pt}} + +%% III.2 - Colors + +\definecolor{nicergreen}{rgb}{0,0.502,0} +\definecolor{nicerblue}{rgb}{0,0.302,1} +\definecolor{nicerorange}{rgb}{1,0.502,0} +\definecolor{nicergrey}{rgb}{0.502,0.502,0.502} +\definecolor{nicerred}{rgb}{0.626,0,0} +\definecolor{hintbg}{rgb}{1.0,1.0,0.75} +\definecolor{warnbg}{rgb}{1.0,0.75,0.75} +\definecolor{infobg}{rgb}{0.75,0.75,1.0} +\definecolor{bibliotechbg}{RGB}{239,253,255} +\definecolor{lightgrey}{rgb}{0.95,0.95,0.95} +\definecolor{darkgrey}{rgb}{0.1,0.1,0.1} +\definecolor{assholeblack}{rgb}{0,0,0} + +%% III.3 - Hyperlinks + +\hypersetup +{ + colorlinks, +% citecolor=black, % +% filecolor=black, % + linkcolor=black, % black links + urlcolor=blue % blue URLs +} + +%% III.4 - Listings + +\lstset +{ + backgroundcolor=\color{gray!15}, + basicstyle=\small\ttfamily, + breaklines=true, + columns=fullflexible, + frame=lines, + tabsize=4, + numbers=none, %numbers=left, + numberstyle=\scriptsize\ttfamily, + numbersep=5pt, + showspaces=false, + showstringspaces=false, + showtabs=false, + breaklines=true, + upquote=true, + float +} + +%% III.5 - Page layout + +\makeatletter +\pagestyle{fancy} +\lhead{\@title} +\rhead{\@subtitle} +\cfoot{\thepage} +\makeatother + +%% III.6 - Roman chapter style + +% custom sections style + +\renewcommand{\thechapter}{\Roman{chapter}} + +% Using roman numerals makes the TOC section/subsection numbers +% overflow on the right. This adds some margin to avoid that kind of +% problems. (requires \usepackage{tocloft}) +\setlength{\cftchapnumwidth}{1.5cm} +\setlength{\cftsecnumwidth}{1.5cm} +\setlength{\cftsubsecnumwidth}{1.3cm} +\setlength{\cftsubsubsecnumwidth}{1.6cm} +\setlength{\cftaftertoctitleskip}{0.5cm} + +%% IV - Frontpage customization + +%% IV.1 - Custom fields +\makeatletter +\newcommand{\website}[1]{\def \@website {#1}} +\website{} + +\newcommand{\subtitle}[1]{\def \@subtitle {#1}} +\subtitle{} + +\newcommand{\schoollogo}[1]{\def \@schoollogo {#1}} +\schoollogo{42_logo.pdf} + +\newcommand{\summary}[1]{\def \@summary {#1}} +\summary{} + +\newcommand{\version}[1]{\def \@version {#1}} +\version{} + +\edef\@authors{} +\newcommand{\member}[2]{% + \protected@edef\@authors{\@authors #1 \protect\url{#2}\\} + \author{\@authors} +} +\author{} + +%% IV.2 - Redefine \maketitle + +\makeatletter +\def \maketitle { + \begin{titlepage} + \begin{center} + %\begin{figure}[t] + \includegraphics[height=8cm]{\@schoollogo} + %\end{figure} + \vskip 5em + {\huge \@title} + \vskip 2em + {\LARGE \@subtitle} + \vskip 4em + \end{center} + \begin{center} + \@author + \end{center} + \vskip 5em + \begin{center} + \emph{\summarytitle : \@summary} + \end{center} + \begin{center} + \emph{\versiontitle : \@version} + \end{center} + \end{titlepage} +} +\makeatother + +\TileWallPaper{\paperwidth}{\paperheight}{back} +%% IV.3 - Exercice number + +\newcounter{exerciceCounter} +\newcommand*{\exercicenumber}{ + \ifnum\value{exerciceCounter}<10 0\fi + \arabic{exerciceCounter} +} + +\newcommand*{\startexercices}{ + \setcounter{exerciceCounter}{0} +} + +\newcommand*{\nextexercice}{ + \stepcounter{exerciceCounter} +} + +\newcounter{itemizeCounter} +\setcounter{itemizeCounter}{0} +\BeforeBegin{itemize}{ + \addtocounter{itemizeCounter}{1} +} + +\AfterEnd{itemize}{ + \addtocounter{itemizeCounter}{-1} + \ifnum\value{itemizeCounter} = 0 + \stepcounter{exerciceCounter} + \fi +} + +%% V - Custom helper commands + +%% V.1 - Hint/Warn + +% hint command + +\newcommand{\kbox}[3] +{ + \vskip 15pt + \noindent + \colorbox{#1} + { + \begin{tabular*}{0.97\textwidth}{m{4em}m{0.8\textwidth}} + \includegraphics[width=4em]{#2} + & {\ttfamily\footnotesize #3}\\ + \end{tabular*} + } + \vskip 15pt +} + +\newcommand{\hint}[1]{\kbox{hintbg}{helphint.pdf}{#1}} +\newcommand{\warn}[1]{\kbox{warnbg}{warn.pdf}{#1}} +\newcommand{\info}[1]{\kbox{infobg}{info.pdf}{#1}} + +%% V.2 Lisibility helper + +\makeatletter +\newcommand{\mso}[1]{ + \ttfamily #1 \normalfont +} + +%% V.3 Exercise headers + +\makeatletter +\newcommand{\turnindir}[1]{\def \@turnindir {#1}} +\newcommand{\daypiscine}[1]{\def \@daypiscine {#1}} +\newcommand{\extitle}[1]{\def \@extitle {#1}} +\newcommand{\exnumber}[1]{\def \@exnumber {#1}} +\newcommand{\exscore}[1]{\def \@exscore {#1}} +\newcommand{\exflags}[1][-W -Wall -Werror]{\def \@exflags {#1}} +\newcommand{\excompil}[1][gcc]{\def \@excompil {#1}} +\newcommand{\exrules}[1][n/a]{\def \@exrules {#1}} +\newcommand{\exfiles}[1]{\def \@exfiles {#1}} +\newcommand{\exnotes}[1][n/a]{\def \@exnotes {#1}} +\newcommand{\exauthorize}[1]{\def \@exauthorize {#1}} +\newcommand{\exforbidden}[1]{\def \@exforbidden {#1}} +\newcommand{\exmake}[1][No]{\def \@exmake {#1}} + +% Default values +\turnindir{} +\daypiscine{} +\extitle{} +\exnumber{} +\exscore{} +\exflags{} +\excompil{} +\exrules{} +\exfiles{} +\exnotes{} +\exauthorize{None} +\exforbidden{None} +\exmake{} + +%Header pour exercices sans rien a "rendre" +\newcommand{\makeheaderbasic} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercise : \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + +%% \multicolumn{4}{|>{\raggedright}m{15cm}|} +%% {\small Notes : \ttfamily \@exnotes } +%% \\ \hline +\end{tabularx} +%% \exnotes +\exrules +\exmake +%\exauthorize +\exforbidden{None} +\extitle{} +\exnumber{} +} + +%Header pour exercices sans code mais fichiers a rendre +\newcommand{\makeheaderfiles} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercise \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Turn-in directory : \ttfamily + $ex\@exnumber/$ } + \\ \hline + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Files to turn in : \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Allowed functions : \ttfamily \@exauthorize } + \\ \hline + +%% \multicolumn{4}{|>{\raggedright}m{15cm}|} +%% {\small Notes : \ttfamily \@exnotes } +%% \\ \hline +\end{tabularx} +%% \exnotes +\exrules +\exmake +\exauthorize{None} +\exforbidden{None} +\extitle{} +\exnumber{} +} + +%Header for exercices without turn in repository +\newcommand{\makeheaderfilesnodirectory} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercice : \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Files to turn in : \ttfamily \@exauthorize } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Authorised functions : \ttfamily \@exnotes } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Notes : \ttfamily \@exnotes } + \\ \hline +\end{tabularx} +\exnotes +\exrules +\exmake +\exauthorize{None} +\exforbidden{None} +\extitle{} +\exnumber{} +} + +%Header pour exercices sans code mais fichiers a rendre +\newcommand{\makeheaderfilesforbidden} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercise : \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Turn-in directory : \ttfamily + $ex\@exnumber/$ } + \\ \hline + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Files to turn in : \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Forbidden functions : \ttfamily \@exforbidden } + \\ \hline + +%% \multicolumn{4}{|>{\raggedright}m{15cm}|} +%% {\small Remarks : \ttfamily \@exnotes } +%% \\ \hline +\end{tabularx} +%% \exnotes +\exrules +\exmake +\exauthorize{None} +\exforbidden{None} +\extitle{} +\exnumber{} +} + +%Header pour exercices de code +\newcommand{\makeheadercode} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercise \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} + %% {\scriptsize Score : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Turn-in directory: \ttfamily + $ex\@exnumber/$ } + \\ \hline + + \multicolumn{2}{|>{\raggedright}m{7.5cm}} + {\small Compiler: \ttfamily \@excompil } & + \multicolumn{2}{|>{\raggedright}m{7.5cm}|} + {\small Compilation flags: + \ttfamily \@exflags } + \\ \hline + + \multicolumn{2}{|>{\raggedright}m{7.52cm}} + {\small Makefile: \ttfamily{\@exmake}} & + \multicolumn{2}{|>{\raggedright}m{7.5cm}|} + {Makefile rules: \ttfamily \@exrules } \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Files to turn in: \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Notes : \ttfamily \@exnotes } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Forbidden fonctions: \ttfamily \@exforbidden } + \\ \hline +\end{tabularx} +\exnotes +\exrules +\exmake +\exforbidden{None} +\extitle{} +\exnumber{} +} + + +\newcommand{\ftname}[1]{\def \@ftname {#1}} +\newcommand{\ftprototype}[1]{\def \@ftprototype {#1}} +\newcommand{\ftdesc}[1]{\def \@ftdesc {#1}} +\newcommand{\ftparams}[1]{\def \@ftparams {#1}} +\newcommand{\ftret}[1]{\def \@ftret {#1}} +\newcommand{\ftfuncts}[1]{\def \@ftfuncts {#1}} +\newcommand{\ftturnin}[1]{\def \@ftturnin {#1}} +\newcommand{\ftmakefile}[1]{\def \@ftmakefile {#1}} +\newcommand{\ftlibft}[1]{\def \@ftlibft {#1}} +\newcommand{\ftcompil}[1]{\def \@ftcompil {#1}} + +\ftname{} +\ftprototype{} +\ftdesc{} +\ftparams{} +\ftret{} +\ftfuncts{} +\ftturnin{} +\ftmakefile{} +\ftlibft{} +\ftcompil{} + + +\newcolumntype{s}{>{\hsize=.5\hsize}X} +\newcolumntype{b}{>{\hsize=1.5\hsize}X} +\newcommand{\makeheaderfct} +{ + \noindent + + \begin{tabularx}{\textwidth}{| s | b |} \hline + + \textbf{Function name} & \texttt{\@ftname} \\ \hline + \textbf{Prototype} & \texttt{\@ftprototype} \\ \hline + \textbf{Turn in files} & \texttt{\@ftturnin} \\ \hline + \textbf{Parameters} & \texttt{\@ftparams} \\ \hline + \textbf{Return value} & \texttt{\@ftret} \\ \hline + \textbf{External functs.} & \texttt{\@ftfuncts} \\ \hline + \textbf{Description} & \texttt{\@ftdesc} \\ \hline + +\end{tabularx} +} + +\newcommand{\makeheaderlib} +{ + \noindent + + \begin{tabularx}{\textwidth}{| s | b |} \hline + + \textbf{Program name} & \texttt{\@ftname} \\ \hline + \textbf{Turn in files} & \texttt{\@ftturnin} \\ \hline + \textbf{Makefile} & \texttt{\@ftmakefile} \\ \hline + \textbf{External functs.} & \texttt{\@ftfuncts} \\ \hline + \textbf{Libft authorized} & \texttt{\@ftlibft} \\ \hline + \textbf{Description} & \texttt{\@ftdesc} \\ \hline + +\end{tabularx} +} + +\newcommand{\makeheaderprg} +{ + \noindent + + \begin{tabularx}{\textwidth}{| s | b |} \hline + + \textbf{Program name} & \texttt{\@ftname} \\ \hline + \textbf{Turn in files} & \texttt{\@ftturnin} \\ \hline + \textbf{Makefile} & \texttt{\@ftmakefile} \\ \hline + \textbf{Arguments} & \texttt{\@ftparams} \\ \hline + \textbf{External functs.} & \texttt{\@ftfuncts} \\ \hline + \textbf{Libft authorized} & \texttt{\@ftlibft} \\ \hline + \textbf{Description} & \texttt{\@ftdesc} \\ \hline + +\end{tabularx} +} + + +\newcommand{\exmandatory}{Mandatory exercise} +\newcommand{\exretrovalid}{Retrovalidated exercise} +\newcommand{\exoptional}{Optional exercise} + +\newcommand{\exercice}{Exercise} + +%% V.4 Reproduction from man +\newcommand{\reproductionfromman}[1]{Reproduce the behavior of the function \texttt{#1} (man #1).} + +%% VI - Syntactic highlights + + +%% Styles: +%% ~~~~~~~ +%% * monokai: +%% This style mimics the Monokai color scheme. +%% * manni: +%% A colorful style, inspired by the terminal highlighting style. +%% * rrt: +%% Minimalistic ``rrt'' theme, based on Zap and Emacs defaults. +%% * perldoc: +%% Style similar to the style used in the perldoc code blocks. +%% * borland: +%% Style similar to the style used in the borland IDEs. +%% * colorful: +%% A colorful style, inspired by CodeRay. +%% * default: +%% The default style (inspired by Emacs 22). +%% * murphy: +%% Murphy's style from CodeRay. +%% * vs: +%% +%% * trac: +%% Port of the default trac highlighter design. +%% * tango: +%% The Crunchy default Style inspired from the color palette from the Tango Icon Theme Guidelines. +%% * fruity: +%% Pygments version of the ``native'' vim theme. +%% * autumn: +%% A colorful style, inspired by the terminal highlighting style. +%% * bw: +%% +%% * emacs: +%% The default style (inspired by Emacs 22). +%% * vim: +%% Styles somewhat like vim 7.0 +%% * pastie: +%% Style similar to the pastie default style. +%% * friendly: +%% A modern style based on the VIM pyte theme. +%% * native: +%% Pygments version of the ``native'' vim theme. + + + +%\usemintedstyle{monokai} +%\usemintedstyle{manni} +%\usemintedstyle{rrt} +%\usemintedstyle{perldoc} +%\usemintedstyle{borland} +%\usemintedstyle{colorful} +%\usemintedstyle{default} +%\usemintedstyle{murphy} +%\usemintedstyle{vs} +%\usemintedstyle{trac} +%\usemintedstyle{tango} +%\usemintedstyle{fruity} +%\usemintedstyle{autumn} +%\usemintedstyle{bw} +%\usemintedstyle{emacs} +%\usemintedstyle{vim} +%\usemintedstyle{pastie} +%\usemintedstyle{friendly} +%\usemintedstyle{native} + +\makeatletter +\newenvironment{42ccode}{% + \VerbatimEnvironment + \usemintedstyle{emacs} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{c} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42phpcode}{% + \VerbatimEnvironment + \usemintedstyle{emacs} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{html+php} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42jscode}{% + \VerbatimEnvironment + \usemintedstyle{emacs} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{js} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\definecolor{darcula-back}{RGB}{35, 37, 37} + +\makeatletter +\newenvironment{42javacode}{% + \VerbatimEnvironment + \usemintedstyle{monokai} + \minted@resetoptions + \definecolor{dark}{RGB}{35, 37, 37} + \setkeys{minted@opt}{bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{java} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42xmlcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{xml} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42yamlcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{yaml} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42cppcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{c++} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + + +\makeatletter +\newenvironment{42ocamlcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{ocaml} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + + +\makeatletter +\newenvironment{42asmcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{nasm} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\lstnewenvironment{42console} { + \lstset { + extendedchars=true, + literate={✓}{{\checkmark}}1, + basicstyle=\color{lightgrey}\scriptsize\ttfamily, + backgroundcolor=\color{assholeblack}, + breaklines=true, + numberstyle=\scriptsize, + columns=flexible, + keepspaces=false, + } +}{} + +\newenvironment{42warning} + {\vspace*{1\baselineskip} + \par\begin{mdframed}[linewidth=2pt,linecolor=red]% + \begin{list}{}{\leftmargin=1cm + \labelwidth=\leftmargin}\item[\Large\ding{43}]} + {\end{list}\end{mdframed}\par \vspace*{1\baselineskip}} \ No newline at end of file diff --git a/resources/latex/42-es.cls b/resources/latex/42-es.cls new file mode 100644 index 00000000..2b86ed09 --- /dev/null +++ b/resources/latex/42-es.cls @@ -0,0 +1,895 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% 42.cls +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% Authors: +% - Maxime "zaz" Montinet +% - David "Thor" Giron +% +% Contributors: +% - Mathieu Mahé +% - Gaëtan JUVIN +% - Unknown for now +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +% This class provides a layout for teaching material at 42. +% +% This class is organized this way : +% +% I - Documentation +% 1. Incompatibilites +% II - General LaTeX boilerplate +% 1. Definition +% 2. Class options and parent class +% 3. Imports +% III - Lengths and color redefinitions +% 1. Lenghts +% 2. Colors +% 3. Hyperlinks +% 4. Listings +% 5. Page layout +% 6. Roman numerals for chapters +% IV - Frontpage customization +% 1. Custom fields +% 2. Redefinition of \maketitle +% 3. Exercice number +% V - Custom helper commands +% 1. Hint/warn +% 2. Lisibility helper +% 3. Exercise headers +% 4. Reproduction from man + +%% +%% I - Documentation +%% + +%% I.1 - Incompatibilities + +% Package ulem: +% The package ulem has a lot of oddities. Using it is not always a +% good idea. If you really want to do so, you should import it with +% the [normalem] option, as such : +% \usepackage[normalem]{ulem} +% Otherwise, it overrides \emph to underline the emphasized text. So +% far so good, but underlined text is typesetted in a box, which means +% that linebreaks don't happen automatically. Since \abstract (among +% others) uses \emph, the abstract is unreadable by default. +% Please read thoroughly ulem's doc before using it. +% See also: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=underline + +%% +%% II - General LaTeX boilerplate +%% + +%% II.1 - Definition + +\NeedsTeXFormat{LaTeX2e}[1995/12/01] +\ProvidesClass{42-es}[2014/08/22 v2.1 + LaTeX class for 42-themed documents] + +%% II.2 - Class options and parent class + +\newcommand{\summarytitle}{Resumen}% + +\newcommand{\versiontitle}{Versión}% + +\DeclareOption*{% + \PassOptionsToClass{\CurrentOption}{report} +} + +\ProcessOptions\relax +\LoadClass[a4paper,12pt,onecolumn]{report} + +%% II.3 - Imports + +\usepackage[top=1in,bottom=1in,left=1in,right=1in]{geometry} +\usepackage[pdftex]{graphicx} +\usepackage{url} +\usepackage{fancyhdr} +\usepackage{array} +\usepackage[table]{xcolor} +\usepackage[utf8]{inputenc} +\usepackage[T1]{fontenc} +\usepackage{lmodern} +\usepackage{listings} +\usepackage{tabularx} +\usepackage{textcomp} +\usepackage{color} +\usepackage[pdftex]{hyperref} +\usepackage{fancybox} +\usepackage{float} +\usepackage{atbeginend} % provided locally : atbeginend.sty +\usepackage{tocloft} % provided locally : tocloft.sty +\usepackage{multirow} % provided locally : multirow.sty +\usepackage[spanish]{babel} +\usepackage{minted} % provided locally : minted.sty +% Minted requires the Python "Pygments" librairy (http://pygments.org/). +% Pygments can be easily installed with the "easy_install" paquet manager +% from the "python-setuptools" paquet (sudo easy_install Pygments). +\usepackage{pifont,mdframed} +\usepackage{wallpaper} + +%% III - Lengths and color redefinitions + +%% III.1 - Lengths + +\AfterBegin{enumerate}{ + \itemsep10pt% +} +\AfterBegin{itemize}{ + \itemsep5pt% + \renewcommand{\labelitemi}{$\bullet$}% + \renewcommand{\labelitemii}{$\circ$}% +} + +\BeforeBegin{enumerate}{\vspace{15pt}} +\AfterEnd{enumerate}{\vspace{15pt}} + +\BeforeBegin{itemize}{\vspace{15pt}} +\AfterEnd{itemize}{\vspace{15pt}} + +\BeforeBegin{lstlisting}{\vspace{15pt}} +\AfterEnd{lstlisting}{\vspace{15pt}} + +\BeforeBegin{tabularx}{\vspace{15pt}} +\AfterEnd{tabularx}{\vspace{15pt}} + +%% III.2 - Colors + +\definecolor{nicergreen}{rgb}{0,0.502,0} +\definecolor{nicerblue}{rgb}{0,0.302,1} +\definecolor{nicerorange}{rgb}{1,0.502,0} +\definecolor{nicergrey}{rgb}{0.502,0.502,0.502} +\definecolor{nicerred}{rgb}{0.626,0,0} +\definecolor{hintbg}{rgb}{1.0,1.0,0.75} +\definecolor{warnbg}{rgb}{1.0,0.75,0.75} +\definecolor{infobg}{rgb}{0.75,0.75,1.0} +\definecolor{bibliotechbg}{RGB}{239,253,255} +\definecolor{lightgrey}{rgb}{0.95,0.95,0.95} +\definecolor{darkgrey}{rgb}{0.1,0.1,0.1} +\definecolor{assholeblack}{rgb}{0,0,0} + +%% III.3 - Hyperlinks + +\hypersetup +{ + colorlinks, +% citecolor=black, % +% filecolor=black, % + linkcolor=black, % black links + urlcolor=blue % blue URLs +} + +%% III.4 - Listings + +\lstset +{ + backgroundcolor=\color{gray!15}, + basicstyle=\small\ttfamily, + breaklines=true, + columns=fullflexible, + frame=lines, + tabsize=4, + numbers=none, %numbers=left, + numberstyle=\scriptsize\ttfamily, + numbersep=5pt, + showspaces=false, + showstringspaces=false, + showtabs=false, + breaklines=true, + upquote=true, + float +} + +%% III.5 - Page layout + +\makeatletter +\pagestyle{fancy} +\lhead{\@title} +\rhead{\@subtitle} +\cfoot{\thepage} +\makeatother + +%% III.6 - Roman chapter style + +% custom sections style + +\renewcommand{\thechapter}{\Roman{chapter}} + +% Using roman numerals makes the TOC section/subsection numbers +% overflow on the right. This adds some margin to avoid that kind of +% problems. (requires \usepackage{tocloft}) +\setlength{\cftchapnumwidth}{1.5cm} +\setlength{\cftsecnumwidth}{1.5cm} +\setlength{\cftsubsecnumwidth}{1.3cm} +\setlength{\cftsubsubsecnumwidth}{1.6cm} +\setlength{\cftaftertoctitleskip}{0.5cm} + +%% IV - Frontpage customization + +%% IV.1 - Custom fields +\makeatletter +\newcommand{\website}[1]{\def \@website {#1}} +\website{} + +\newcommand{\subtitle}[1]{\def \@subtitle {#1}} +\subtitle{} + +\newcommand{\schoollogo}[1]{\def \@schoollogo {#1}} +\schoollogo{42_logo.pdf} + +\newcommand{\summary}[1]{\def \@summary {#1}} +\summary{} + +\newcommand{\version}[1]{\def \@version {#1}} +\version{} + +\edef\@authors{} +\newcommand{\member}[2]{% + \protected@edef\@authors{\@authors #1 \protect\url{#2}\\} + \author{\@authors} +} +\author{} + +%% IV.2 - Redefine \maketitle + +\makeatletter +\def \maketitle { + \begin{titlepage} + \begin{center} + %\begin{figure}[t] + \includegraphics[height=8cm]{\@schoollogo} + %\end{figure} + \vskip 5em + {\huge \@title} + \vskip 2em + {\LARGE \@subtitle} + \vskip 4em + \end{center} + \begin{center} + \@author + \end{center} + \vskip 5em + \begin{center} + \emph{\summarytitle : \@summary} + \end{center} + \begin{center} + \emph{\versiontitle : \@version} + \end{center} + \end{titlepage} +} +\makeatother + +\TileWallPaper{\paperwidth}{\paperheight}{back} +%% IV.3 - Exercice number + +\newcounter{exerciceCounter} +\newcommand*{\exercicenumber}{ + \ifnum\value{exerciceCounter}<10 0\fi + \arabic{exerciceCounter} +} + +\newcommand*{\startexercices}{ + \setcounter{exerciceCounter}{0} +} + +\newcommand*{\nextexercice}{ + \stepcounter{exerciceCounter} +} + +\newcounter{itemizeCounter} +\setcounter{itemizeCounter}{0} +\BeforeBegin{itemize}{ + \addtocounter{itemizeCounter}{1} +} + +\AfterEnd{itemize}{ + \addtocounter{itemizeCounter}{-1} + \ifnum\value{itemizeCounter} = 0 + \stepcounter{exerciceCounter} + \fi +} + +%% V - Custom helper commands + +%% V.1 - Hint/Warn + +% hint command + +\newcommand{\kbox}[3] +{ + \vskip 15pt + \noindent + \colorbox{#1} + { + \begin{tabular*}{0.97\textwidth}{m{4em}m{0.8\textwidth}} + \includegraphics[width=4em]{#2} + & {\ttfamily\footnotesize #3}\\ + \end{tabular*} + } + \vskip 15pt +} + +\newcommand{\hint}[1]{\kbox{hintbg}{helphint.pdf}{#1}} +\newcommand{\warn}[1]{\kbox{warnbg}{warn.pdf}{#1}} +\newcommand{\info}[1]{\kbox{infobg}{info.pdf}{#1}} + +%% V.2 Lisibility helper + +\makeatletter +\newcommand{\mso}[1]{ + \ttfamily #1 \normalfont +} + +%% V.3 Exercise headers + +\makeatletter +\newcommand{\turnindir}[1]{\def \@turnindir {#1}} +\newcommand{\daypiscine}[1]{\def \@daypiscine {#1}} +\newcommand{\extitle}[1]{\def \@extitle {#1}} +\newcommand{\exnumber}[1]{\def \@exnumber {#1}} +\newcommand{\exscore}[1]{\def \@exscore {#1}} +\newcommand{\exflags}[1][-W -Wall -Werror]{\def \@exflags {#1}} +\newcommand{\excompil}[1][gcc]{\def \@excompil {#1}} +\newcommand{\exrules}[1][n/a]{\def \@exrules {#1}} +\newcommand{\exfiles}[1]{\def \@exfiles {#1}} +\newcommand{\exnotes}[1][n/a]{\def \@exnotes {#1}} +\newcommand{\exauthorize}[1]{\def \@exauthorize {#1}} +\newcommand{\exforbidden}[1]{\def \@exforbidden {#1}} +\newcommand{\exmake}[1][No]{\def \@exmake {#1}} + +% Default values +\turnindir{} +\daypiscine{} +\extitle{} +\exnumber{} +\exscore{} +\exflags{} +\excompil{} +\exrules{} +\exfiles{} +\exnotes{} +\exauthorize{Ninguna} +\exforbidden{Ninguna} +\exmake{} + +%Header pour exercices sans rien a "rendre" +\newcommand{\makeheaderbasic} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Ejercicio: \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + +%% \multicolumn{4}{|>{\raggedright}m{15cm}|} +%% {\small Notes : \ttfamily \@exnotes } +%% \\ \hline +\end{tabularx} +%% \exnotes +\exrules +\exmake +%\exauthorize +\exforbidden{Ninguna} +\extitle{} +\exnumber{} +} + +%Header pour exercices sans code mais fichiers a rendre +\newcommand{\makeheaderfiles} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Ejercicio: \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Directorio de entrega: \ttfamily + $ex\@exnumber/$ } + \\ \hline + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Archivos a entregar: \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Funciones autorizadas: \ttfamily \@exauthorize } + \\ \hline + +%% \multicolumn{4}{|>{\raggedright}m{15cm}|} +%% {\small Notes : \ttfamily \@exnotes } +%% \\ \hline +\end{tabularx} +%% \exnotes +\exrules +\exmake +\exauthorize{Ninguna} +\exforbidden{Ninguna} +\extitle{} +\exnumber{} +} + +%Header for exercices without turn in repository +\newcommand{\makeheaderfilesnodirectory} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Ejercicio: \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Archivos a entregar: \ttfamily \@exauthorize } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Funciones autorizadas: \ttfamily \@exnotes } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Nota: \ttfamily \@exnotes } + \\ \hline +\end{tabularx} +\exnotes +\exrules +\exmake +\exauthorize{Ninguna} +\exforbidden{Ninguna} +\extitle{} +\exnumber{} +} + +%Header pour exercices sans code mais fichiers a rendre +\newcommand{\makeheaderfilesforbidden} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Ejercicio: \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Directorio de entrega: \ttfamily + $ex\@exnumber/$ } + \\ \hline + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Archivos de entrega: \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Funciones prohibidas: \ttfamily \@exforbidden } + \\ \hline + +%% \multicolumn{4}{|>{\raggedright}m{15cm}|} +%% {\small Remarks : \ttfamily \@exnotes } +%% \\ \hline +\end{tabularx} +%% \exnotes +\exrules +\exmake +\exauthorize{Ninguna} +\exforbidden{Ninguna} +\extitle{} +\exnumber{} +} + +%Header pour exercices de code +\newcommand{\makeheadercode} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Ejercicio \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} + %% {\scriptsize Score : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Directorio de entrega: \ttfamily + $ex\@exnumber/$ } + \\ \hline + + \multicolumn{2}{|>{\raggedright}m{7.5cm}} + {\small Compilador: \ttfamily \@excompil } & + \multicolumn{2}{|>{\raggedright}m{7.5cm}|} + {\small Flags de compilación: + \ttfamily \@exflags } + \\ \hline + + \multicolumn{2}{|>{\raggedright}m{7.52cm}} + {\small Makefile: \ttfamily{\@exmake}} & + \multicolumn{2}{|>{\raggedright}m{7.5cm}|} + {Reglas de Makefile: \ttfamily \@exrules } \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Archivos a entregar: \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Nota: \ttfamily \@exnotes } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Funciones prohibidas: \ttfamily \@exforbidden } + \\ \hline +\end{tabularx} +\exnotes +\exrules +\exmake +\exforbidden{Ninguna} +\extitle{} +\exnumber{} +} + + +\newcommand{\ftname}[1]{\def \@ftname {#1}} +\newcommand{\ftprototype}[1]{\def \@ftprototype {#1}} +\newcommand{\ftdesc}[1]{\def \@ftdesc {#1}} +\newcommand{\ftparams}[1]{\def \@ftparams {#1}} +\newcommand{\ftret}[1]{\def \@ftret {#1}} +\newcommand{\ftfuncts}[1]{\def \@ftfuncts {#1}} +\newcommand{\ftturnin}[1]{\def \@ftturnin {#1}} +\newcommand{\ftmakefile}[1]{\def \@ftmakefile {#1}} +\newcommand{\ftlibft}[1]{\def \@ftlibft {#1}} +\newcommand{\ftcompil}[1]{\def \@ftcompil {#1}} + +\ftname{} +\ftprototype{} +\ftdesc{} +\ftparams{} +\ftret{} +\ftfuncts{} +\ftturnin{} +\ftmakefile{} +\ftlibft{} +\ftcompil{} + + +\newcolumntype{s}{>{\hsize=.5\hsize}X} +\newcolumntype{b}{>{\hsize=1.5\hsize}X} +\newcommand{\makeheaderfct} +{ + \noindent + + \begin{tabularx}{\textwidth}{| s | b |} \hline + + \textbf{Nombre de función} & \texttt{\@ftname} \\ \hline + \textbf{Prototipo} & \texttt{\@ftprototype} \\ \hline + \textbf{Archivos a entregar} & \texttt{\@ftturnin} \\ \hline + \textbf{Parámetros} & \texttt{\@ftparams} \\ \hline + \textbf{Valor devuelto} & \texttt{\@ftret} \\ \hline + \textbf{Funciones autorizadas} & \texttt{\@ftfuncts} \\ \hline + \textbf{Descripción} & \texttt{\@ftdesc} \\ \hline + +\end{tabularx} +} + +\newcommand{\makeheaderlib} +{ + \noindent + + \begin{tabularx}{\textwidth}{| s | b |} \hline + + \textbf{Nombre de programa} & \texttt{\@ftname} \\ \hline + \textbf{Archivos a entregar} & \texttt{\@ftturnin} \\ \hline + \textbf{Makefile} & \texttt{\@ftmakefile} \\ \hline + \textbf{Funciones autorizadas} & \texttt{\@ftfuncts} \\ \hline + \textbf{Se permite usar libft} & \texttt{\@ftlibft} \\ \hline + \textbf{Descripción} & \texttt{\@ftdesc} \\ \hline + +\end{tabularx} +} + +\newcommand{\makeheaderprg} +{ + \noindent + + \begin{tabularx}{\textwidth}{| s | b |} \hline + + \textbf{Nombre de programa} & \texttt{\@ftname} \\ \hline + \textbf{Archivos a entregar} & \texttt{\@ftturnin} \\ \hline + \textbf{Makefile} & \texttt{\@ftmakefile} \\ \hline + \textbf{Argumentos} & \texttt{\@ftparams} \\ \hline + \textbf{Funciones autorizadas} & \texttt{\@ftfuncts} \\ \hline + \textbf{Se permite usar libft} & \texttt{\@ftlibft} \\ \hline + \textbf{Descripción} & \texttt{\@ftdesc} \\ \hline + +\end{tabularx} +} + + +\newcommand{\exmandatory}{Ejercicio obligatorio} +\newcommand{\exretrovalid}{Ejercicio retrovalidado} +\newcommand{\exoptional}{Ejercicio opcional} + +\newcommand{\exercice}{Ejercicio} + +%% V.4 Reproduction from man +\newcommand{\reproductionfromman}[1]{Reproduce el comportamiento de la función \texttt{#1} (man #1).} + +%% VI - Syntactic highlights + + +%% Styles: +%% ~~~~~~~ +%% * monokai: +%% This style mimics the Monokai color scheme. +%% * manni: +%% A colorful style, inspired by the terminal highlighting style. +%% * rrt: +%% Minimalistic ``rrt'' theme, based on Zap and Emacs defaults. +%% * perldoc: +%% Style similar to the style used in the perldoc code blocks. +%% * borland: +%% Style similar to the style used in the borland IDEs. +%% * colorful: +%% A colorful style, inspired by CodeRay. +%% * default: +%% The default style (inspired by Emacs 22). +%% * murphy: +%% Murphy's style from CodeRay. +%% * vs: +%% +%% * trac: +%% Port of the default trac highlighter design. +%% * tango: +%% The Crunchy default Style inspired from the color palette from the Tango Icon Theme Guidelines. +%% * fruity: +%% Pygments version of the ``native'' vim theme. +%% * autumn: +%% A colorful style, inspired by the terminal highlighting style. +%% * bw: +%% +%% * emacs: +%% The default style (inspired by Emacs 22). +%% * vim: +%% Styles somewhat like vim 7.0 +%% * pastie: +%% Style similar to the pastie default style. +%% * friendly: +%% A modern style based on the VIM pyte theme. +%% * native: +%% Pygments version of the ``native'' vim theme. + + + +%\usemintedstyle{monokai} +%\usemintedstyle{manni} +%\usemintedstyle{rrt} +%\usemintedstyle{perldoc} +%\usemintedstyle{borland} +%\usemintedstyle{colorful} +%\usemintedstyle{default} +%\usemintedstyle{murphy} +%\usemintedstyle{vs} +%\usemintedstyle{trac} +%\usemintedstyle{tango} +%\usemintedstyle{fruity} +%\usemintedstyle{autumn} +%\usemintedstyle{bw} +%\usemintedstyle{emacs} +%\usemintedstyle{vim} +%\usemintedstyle{pastie} +%\usemintedstyle{friendly} +%\usemintedstyle{native} + +\makeatletter +\newenvironment{42ccode}{% + \VerbatimEnvironment + \usemintedstyle{emacs} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{c} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42phpcode}{% + \VerbatimEnvironment + \usemintedstyle{emacs} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{html+php} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42jscode}{% + \VerbatimEnvironment + \usemintedstyle{emacs} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{js} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\definecolor{darcula-back}{RGB}{35, 37, 37} + +\makeatletter +\newenvironment{42javacode}{% + \VerbatimEnvironment + \usemintedstyle{monokai} + \minted@resetoptions + \definecolor{dark}{RGB}{35, 37, 37} + \setkeys{minted@opt}{bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{java} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42xmlcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{xml} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42yamlcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{yaml} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42cppcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{c++} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + + +\makeatletter +\newenvironment{42ocamlcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{ocaml} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + + +\makeatletter +\newenvironment{42asmcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{nasm} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\lstnewenvironment{42console} { + \lstset { + extendedchars=true, + literate={✓}{{\checkmark}}1, + basicstyle=\color{lightgrey}\scriptsize\ttfamily, + backgroundcolor=\color{assholeblack}, + breaklines=true, + numberstyle=\scriptsize, + columns=flexible, + keepspaces=false, + } +}{} + +\newenvironment{42warning} + {\vspace*{1\baselineskip} + \par\begin{mdframed}[linewidth=2pt,linecolor=red]% + \begin{list}{}{\leftmargin=1cm + \labelwidth=\leftmargin}\item[\Large\ding{43}]} + {\end{list}\end{mdframed}\par \vspace*{1\baselineskip}} diff --git a/resources/latex/42-fr.cls b/resources/latex/42-fr.cls new file mode 100644 index 00000000..977014da --- /dev/null +++ b/resources/latex/42-fr.cls @@ -0,0 +1,895 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% 42.cls +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% Authors: +% - Maxime "zaz" Montinet +% - David "Thor" Giron +% +% Contributors: +% - Mathieu Mahé +% - Gaëtan JUVIN +% - Unknown for now +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +% This class provides a layout for teaching material at 42. +% +% This class is organized this way : +% +% I - Documentation +% 1. Incompatibilites +% II - General LaTeX boilerplate +% 1. Definition +% 2. Class options and parent class +% 3. Imports +% III - Lengths and color redefinitions +% 1. Lenghts +% 2. Colors +% 3. Hyperlinks +% 4. Listings +% 5. Page layout +% 6. Roman numerals for chapters +% IV - Frontpage customization +% 1. Custom fields +% 2. Redefinition of \maketitle +% 3. Exercice number +% V - Custom helper commands +% 1. Hint/warn +% 2. Lisibility helper +% 3. Exercise headers +% 4. Reproduction from man + +%% +%% I - Documentation +%% + +%% I.1 - Incompatibilities + +% Package ulem: +% The package ulem has a lot of oddities. Using it is not always a +% good idea. If you really want to do so, you should import it with +% the [normalem] option, as such : +% \usepackage[normalem]{ulem} +% Otherwise, it overrides \emph to underline the emphasized text. So +% far so good, but underlined text is typesetted in a box, which means +% that linebreaks don't happen automatically. Since \abstract (among +% others) uses \emph, the abstract is unreadable by default. +% Please read thoroughly ulem's doc before using it. +% See also: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=underline + +%% +%% II - General LaTeX boilerplate +%% + +%% II.1 - Definition + +\NeedsTeXFormat{LaTeX2e}[1995/12/01] +\ProvidesClass{42-fr}[2010/07/15 v2.0 + LaTeX class for 42-themed documents] + +%% II.2 - Class options and parent class + +\newcommand{\summarytitle}{R\'esum\'e}% + +\newcommand{\versiontitle}{Version}% + +\DeclareOption*{% + \PassOptionsToClass{\CurrentOption}{report} +} + +\ProcessOptions\relax +\LoadClass[a4paper,12pt,onecolumn]{report} + +%% II.3 - Imports + +\usepackage[top=1in,bottom=1in,left=1in,right=1in]{geometry} +\usepackage[pdftex]{graphicx} +\usepackage{url} +\usepackage{fancyhdr} +\usepackage{array} +\usepackage[table]{xcolor} +\usepackage[utf8]{inputenc} +\usepackage[T1]{fontenc} +\usepackage{lmodern} +\usepackage{listings} +\usepackage{tabularx} +\usepackage{textcomp} +\usepackage{color} +\usepackage[pdftex]{hyperref} +\usepackage{fancybox} +\usepackage{float} +\usepackage{atbeginend} % provided locally : atbeginend.sty +\usepackage{tocloft} % provided locally : tocloft.sty +\usepackage{multirow} % provided locally : multirow.sty +\usepackage[french]{babel} +\usepackage{minted} % provided locally : minted.sty +% Minted requires the Python "Pygments" librairy (http://pygments.org/). +% Pygments can be easily installed with the "easy_install" paquet manager +% from the "python-setuptools" paquet (sudo easy_install Pygments). +\usepackage{pifont,mdframed} +\usepackage{wallpaper} + +%% III - Lengths and color redefinitions + +%% III.1 - Lengths + +\AfterBegin{enumerate}{ + \itemsep10pt% +} +\AfterBegin{itemize}{ + \itemsep10pt% + \renewcommand{\labelitemi}{$\bullet$}% + \renewcommand{\labelitemii}{$\circ$}% +} + +\BeforeBegin{enumerate}{\vspace{15pt}} +\AfterEnd{enumerate}{\vspace{15pt}} + +\BeforeBegin{itemize}{\vspace{15pt}} +\AfterEnd{itemize}{\vspace{15pt}} + +\BeforeBegin{lstlisting}{\vspace{15pt}} +\AfterEnd{lstlisting}{\vspace{15pt}} + +\BeforeBegin{tabularx}{\vspace{15pt}} +\AfterEnd{tabularx}{\vspace{15pt}} + +%% III.2 - Colors + +\definecolor{nicergreen}{rgb}{0,0.502,0} +\definecolor{nicerblue}{rgb}{0,0.302,1} +\definecolor{nicerorange}{rgb}{1,0.502,0} +\definecolor{nicergrey}{rgb}{0.502,0.502,0.502} +\definecolor{nicerred}{rgb}{0.626,0,0} +\definecolor{hintbg}{rgb}{1.0,1.0,0.75} +\definecolor{warnbg}{rgb}{1.0,0.75,0.75} +\definecolor{infobg}{rgb}{0.75,0.75,1.0} +\definecolor{bibliotechbg}{RGB}{239,253,255} +\definecolor{lightgrey}{rgb}{0.95,0.95,0.95} +\definecolor{darkgrey}{rgb}{0.1,0.1,0.1} +\definecolor{assholeblack}{rgb}{0,0,0} + +%% III.3 - Hyperlinks + +\hypersetup +{ + colorlinks, +% citecolor=black, % +% filecolor=black, % + linkcolor=black, % black links + urlcolor=blue % blue URLs +} + +%% III.4 - Listings + +\lstset +{ + backgroundcolor=\color{gray!15}, + basicstyle=\small\ttfamily, + breaklines=true, + columns=fullflexible, + frame=lines, + tabsize=4, + numbers=none, %numbers=left, + numberstyle=\scriptsize\ttfamily, + numbersep=5pt, + showspaces=false, + showstringspaces=false, + showtabs=false, + breaklines=true, + upquote=true, + float +} + +%% III.5 - Page layout + +\makeatletter +\pagestyle{fancy} +\lhead{\@title} +\rhead{\@subtitle} +\cfoot{\thepage} +\makeatother + +%% III.6 - Roman chapter style + +% custom sections style + +\renewcommand{\thechapter}{\Roman{chapter}} + +% Using roman numerals makes the TOC section/subsection numbers +% overflow on the right. This adds some margin to avoid that kind of +% problems. (requires \usepackage{tocloft}) +\setlength{\cftchapnumwidth}{1.5cm} +\setlength{\cftsecnumwidth}{1.5cm} +\setlength{\cftsubsecnumwidth}{1.3cm} +\setlength{\cftsubsubsecnumwidth}{1.6cm} +\setlength{\cftaftertoctitleskip}{0.5cm} + +%% IV - Frontpage customization + +%% IV.1 - Custom fields +\makeatletter +\newcommand{\website}[1]{\def \@website {#1}} +\website{} + +\newcommand{\subtitle}[1]{\def \@subtitle {#1}} +\subtitle{} + +\newcommand{\schoollogo}[1]{\def \@schoollogo {#1}} +\schoollogo{42_logo.pdf} + +\newcommand{\summary}[1]{\def \@summary {#1}} +\summary{} + +\newcommand{\version}[1]{\def \@version {#1}} +\version{} + +\edef\@authors{} +\newcommand{\member}[2]{% + \protected@edef\@authors{\@authors #1 \protect\url{#2}\\} + \author{\@authors} +} +\author{} + +%% IV.2 - Redefine \maketitle + +\makeatletter +\def \maketitle { + \begin{titlepage} + \begin{center} + %\begin{figure}[t] + \includegraphics[height=8cm]{\@schoollogo} + %\end{figure} + \vskip 5em + {\huge \@title} + \vskip 2em + {\LARGE \@subtitle} + \vskip 4em + \end{center} + \begin{center} + \@author + \end{center} + \vskip 5em + \begin{center} + \emph{\summarytitle : \@summary} + \end{center} + \begin{center} + \emph{\versiontitle : \@version} + \end{center} + \end{titlepage} +} +\makeatother + +\TileWallPaper{\paperwidth}{\paperheight}{back} +%% IV.3 - Exercice number + +\newcounter{exerciceCounter} +\newcommand*{\exercicenumber}{ + \ifnum\value{exerciceCounter}<10 0\fi + \arabic{exerciceCounter} +} + +\newcommand*{\startexercices}{ + \setcounter{exerciceCounter}{0} +} + +\newcommand*{\nextexercice}{ + \stepcounter{exerciceCounter} +} + +\newcounter{itemizeCounter} +\setcounter{itemizeCounter}{0} +\BeforeBegin{itemize}{ + \addtocounter{itemizeCounter}{1} +} + +\AfterEnd{itemize}{ + \addtocounter{itemizeCounter}{-1} + \ifnum\value{itemizeCounter} = 0 + \stepcounter{exerciceCounter} + \fi +} + +%% V - Custom helper commands + +%% V.1 - Hint/Warn + +% hint command + +\newcommand{\kbox}[3] +{ + \vskip 15pt + \noindent + \colorbox{#1} + { + \begin{tabular*}{0.97\textwidth}{m{4em}m{0.8\textwidth}} + \includegraphics[width=4em]{#2} + & {\ttfamily\footnotesize #3}\\ + \end{tabular*} + } + \vskip 15pt +} + +\newcommand{\hint}[1]{\kbox{hintbg}{helphint.pdf}{#1}} +\newcommand{\warn}[1]{\kbox{warnbg}{warn.pdf}{#1}} +\newcommand{\info}[1]{\kbox{infobg}{info.pdf}{#1}} + +%% V.2 Lisibility helper + +\makeatletter +\newcommand{\mso}[1]{ + \ttfamily #1 \normalfont +} + +%% V.3 Exercise headers + +\makeatletter +\newcommand{\turnindir}[1]{\def \@turnindir {#1}} +\newcommand{\daypiscine}[1]{\def \@daypiscine {#1}} +\newcommand{\extitle}[1]{\def \@extitle {#1}} +\newcommand{\exnumber}[1]{\def \@exnumber {#1}} +\newcommand{\exscore}[1]{\def \@exscore {#1}} +\newcommand{\exflags}[1][-W -Wall -Werror]{\def \@exflags {#1}} +\newcommand{\excompil}[1][gcc]{\def \@excompil {#1}} +\newcommand{\exrules}[1][n/a]{\def \@exrules {#1}} +\newcommand{\exfiles}[1]{\def \@exfiles {#1}} +\newcommand{\exnotes}[1][n/a]{\def \@exnotes {#1}} +\newcommand{\exauthorize}[1]{\def \@exauthorize {#1}} +\newcommand{\exforbidden}[1]{\def \@exforbidden {#1}} +\newcommand{\exmake}[1][Non]{\def \@exmake {#1}} + +% Default values +\turnindir{} +\daypiscine{} +\extitle{} +\exnumber{} +\exscore{} +\exflags{} +\excompil{} +\exrules{} +\exfiles{} +\exnotes{} +\exauthorize{Aucune} +\exforbidden{Aucune} +\exmake{} + +%Header pour exercices sans rien a "rendre" +\newcommand{\makeheaderbasic} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercice : \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + +%% \multicolumn{4}{|>{\raggedright}m{15cm}|} +%% {\small Remarques : \ttfamily \@exnotes } +%% \\ \hline +\end{tabularx} +%% \exnotes +\exrules +\exmake +%\exauthorize +\exforbidden{Aucune} +\extitle{} +\exnumber{} +} + +%Header pour exercices sans code mais fichiers a rendre +\newcommand{\makeheaderfiles} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercice : \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Dossier de rendu : \ttfamily + $ex\@exnumber/$ } + \\ \hline + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Fichiers \`a rendre : \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Fonctions Autoris\'ees : \ttfamily \@exauthorize } + \\ \hline + +%% \multicolumn{4}{|>{\raggedright}m{15cm}|} +%% {\small Remarques : \ttfamily \@exnotes } +%% \\ \hline +\end{tabularx} +%% \exnotes +\exrules +\exmake +\exauthorize{Aucune} +\exforbidden{Aucune} +\extitle{} +\exnumber{} +} + +%Header pour exercices sans dossier de rendu +\newcommand{\makeheaderfilesnodirectory} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercice : \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Fichiers \`a rendre : \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Fonctions Autoris\'ees : \ttfamily \@exauthorize } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Remarques : \ttfamily \@exnotes } + \\ \hline +\end{tabularx} +\exnotes +\exrules +\exmake +\exauthorize{Aucune} +\exforbidden{Aucune} +\extitle{} +\exnumber{} +} + +%Header pour exercices sans code mais fichiers a rendre +\newcommand{\makeheaderfilesforbidden} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercice : \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Dossier de rendu : \ttfamily + $ex\@exnumber/$ } + \\ \hline + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Fichiers \`a rendre : \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Fonctions interdites : \ttfamily \@exforbidden } + \\ \hline + +%% \multicolumn{4}{|>{\raggedright}m{15cm}|} +%% {\small Remarques : \ttfamily \@exnotes } +%% \\ \hline +\end{tabularx} +%% \exnotes +\exrules +\exmake +\exauthorize{Aucune} +\exforbidden{Aucune} +\extitle{} +\exnumber{} +} + + +%Header pour exercices de code +\newcommand{\makeheadercode} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercice : \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} + %% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Dossier de rendu: \ttfamily + $ex\@exnumber/$ } + \\ \hline + + \multicolumn{2}{|>{\raggedright}m{7.5cm}} + {\small Compilateur : \ttfamily \@excompil } & + \multicolumn{2}{|>{\raggedright}m{7.5cm}|} + {\small Flags de compilation: + \ttfamily \@exflags } + \\ \hline + + \multicolumn{2}{|>{\raggedright}m{7.52cm}} + {\small Makefile : \ttfamily{\@exmake}} & + \multicolumn{2}{|>{\raggedright}m{7.5cm}|} + {R\`{e}gles : \ttfamily \@exrules } \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Fichiers \`a rendre : \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Remarques : \ttfamily \@exnotes } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Fonctions Interdites : \ttfamily \@exforbidden } + \\ \hline +\end{tabularx} +\exnotes +\exrules +\exmake +\exforbidden{Aucune} +\extitle{} +\exnumber{} +} + +\newcommand{\ftname}[1]{\def \@ftname {#1}} +\newcommand{\ftprototype}[1]{\def \@ftprototype {#1}} +\newcommand{\ftdesc}[1]{\def \@ftdesc {#1}} +\newcommand{\ftparams}[1]{\def \@ftparams {#1}} +\newcommand{\ftret}[1]{\def \@ftret {#1}} +\newcommand{\ftfuncts}[1]{\def \@ftfuncts {#1}} +\newcommand{\ftturnin}[1]{\def \@ftturnin {#1}} +\newcommand{\ftmakefile}[1]{\def \@ftmakefile {#1}} +\newcommand{\ftlibft}[1]{\def \@ftlibft {#1}} +\newcommand{\ftcompil}[1]{\def \@ftcompil {#1}} + +\ftname{} +\ftprototype{} +\ftdesc{} +\ftparams{} +\ftret{} +\ftfuncts{} +\ftturnin{} +\ftmakefile{} +\ftlibft{} +\ftcompil{} + + +\newcolumntype{s}{>{\hsize=.5\hsize}X} +\newcolumntype{b}{>{\hsize=1.5\hsize}X} +\newcommand{\makeheaderfct} +{ + \noindent + + \begin{tabularx}{\textwidth}{| s | b |} \hline + + \textbf{Function name} & \texttt{\@ftname} \\ \hline + \textbf{Prototype} & \texttt{\@ftprototype} \\ \hline + \textbf{Fichiers de rendu} & \texttt{\@ftturnin} \\ \hline + \textbf{Paramètres} & \texttt{\@ftparams} \\ \hline + \textbf{Valeur de retour} & \texttt{\@ftret} \\ \hline + \textbf{Fonctions externes autorisées} & \texttt{\@ftfuncts} \\ \hline + \textbf{Description} & \texttt{\@ftdesc} \\ \hline + +\end{tabularx} +} + +\newcommand{\makeheaderlib} +{ + \noindent + + \begin{tabularx}{\textwidth}{| s | b |} \hline + + \textbf{Nom du programme} & \texttt{\@ftname} \\ \hline + \textbf{Fichiers de rendu} & \texttt{\@ftturnin} \\ \hline + \textbf{Makefile} & \texttt{\@ftmakefile} \\ \hline + \textbf{Fonctions externes autorisées} & \texttt{\@ftfuncts} \\ \hline + \textbf{Libft autorisée} & \texttt{\@ftlibft} \\ \hline + \textbf{Description} & \texttt{\@ftdesc} \\ \hline + +\end{tabularx} +} + +\newcommand{\makeheaderprg} +{ + \noindent + + \begin{tabularx}{\textwidth}{| s | b |} \hline + + \textbf{Nom du programme} & \texttt{\@ftname} \\ \hline + \textbf{Fichiers de rendu} & \texttt{\@ftturnin} \\ \hline + \textbf{Makefile} & \texttt{\@ftmakefile} \\ \hline + \textbf{Arguments} & \texttt{\@ftparams} \\ \hline + \textbf{Fonctions externes autorisées} & \texttt{\@ftfuncts} \\ \hline + \textbf{Libft autorisée} & \texttt{\@ftlibft} \\ \hline + \textbf{Description} & \texttt{\@ftdesc} \\ \hline + +\end{tabularx} +} + + +\newcommand{\exmandatory}{Exercice obligatoire} +\newcommand{\exretrovalid}{Exercice rétrovalidable} +\newcommand{\exoptional}{Exercice bonus} + +\newcommand{\exercice}{Exercice} + +%% V.4 Reproduction from man +\newcommand{\reproductionfromman}[1]{Reproduire \`a l'identique le fonctionnement de la fonction \texttt{#1} (man #1).} + +%% VI - Syntactic highlights + + +%% Styles: +%% ~~~~~~~ +%% * monokai: +%% This style mimics the Monokai color scheme. +%% * manni: +%% A colorful style, inspired by the terminal highlighting style. +%% * rrt: +%% Minimalistic ``rrt'' theme, based on Zap and Emacs defaults. +%% * perldoc: +%% Style similar to the style used in the perldoc code blocks. +%% * borland: +%% Style similar to the style used in the borland IDEs. +%% * colorful: +%% A colorful style, inspired by CodeRay. +%% * default: +%% The default style (inspired by Emacs 22). +%% * murphy: +%% Murphy's style from CodeRay. +%% * vs: +%% +%% * trac: +%% Port of the default trac highlighter design. +%% * tango: +%% The Crunchy default Style inspired from the color palette from the Tango Icon Theme Guidelines. +%% * fruity: +%% Pygments version of the ``native'' vim theme. +%% * autumn: +%% A colorful style, inspired by the terminal highlighting style. +%% * bw: +%% +%% * emacs: +%% The default style (inspired by Emacs 22). +%% * vim: +%% Styles somewhat like vim 7.0 +%% * pastie: +%% Style similar to the pastie default style. +%% * friendly: +%% A modern style based on the VIM pyte theme. +%% * native: +%% Pygments version of the ``native'' vim theme. + + + +%\usemintedstyle{monokai} +%\usemintedstyle{manni} +%\usemintedstyle{rrt} +%\usemintedstyle{perldoc} +%\usemintedstyle{borland} +%\usemintedstyle{colorful} +%\usemintedstyle{default} +%\usemintedstyle{murphy} +%\usemintedstyle{vs} +%\usemintedstyle{trac} +%\usemintedstyle{tango} +%\usemintedstyle{fruity} +%\usemintedstyle{autumn} +%\usemintedstyle{bw} +%\usemintedstyle{emacs} +%\usemintedstyle{vim} +%\usemintedstyle{pastie} +%\usemintedstyle{friendly} +%\usemintedstyle{native} + +\makeatletter +\newenvironment{42ccode}{% + \VerbatimEnvironment + \usemintedstyle{emacs} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{c} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42phpcode}{% + \VerbatimEnvironment + \usemintedstyle{emacs} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{html+php} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42jscode}{% + \VerbatimEnvironment + \usemintedstyle{emacs} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{js} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\definecolor{darcula-back}{RGB}{35, 37, 37} + +\makeatletter +\newenvironment{42javacode}{% + \VerbatimEnvironment + \usemintedstyle{monokai} + \minted@resetoptions + \definecolor{dark}{RGB}{35, 37, 37} + \setkeys{minted@opt}{bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{java} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42xmlcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{xml} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42yamlcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{yaml} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42cppcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{c++} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + + +\makeatletter +\newenvironment{42ocamlcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{ocaml} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + + +\makeatletter +\newenvironment{42asmcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{nasm} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\lstnewenvironment{42console} { + \lstset { + extendedchars=true, + literate={✓}{{\checkmark}}1, + basicstyle=\color{lightgrey}\scriptsize\ttfamily, + backgroundcolor=\color{assholeblack}, + breaklines=true, + numberstyle=\scriptsize, + columns=flexible, + keepspaces=false, + } +}{} + +\newenvironment{42warning} + {\vspace*{1\baselineskip} + \par\begin{mdframed}[linewidth=2pt,linecolor=red]% + \begin{list}{}{\leftmargin=1cm + \labelwidth=\leftmargin}\item[\Large\ding{43}]} + {\end{list}\end{mdframed}\par \vspace*{1\baselineskip}} diff --git a/resources/latex/42-hy.cls b/resources/latex/42-hy.cls new file mode 100644 index 00000000..6f327719 --- /dev/null +++ b/resources/latex/42-hy.cls @@ -0,0 +1,1803 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% 42.cls +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% Authors: +% - Maxime "zaz" Montinet +% - David "Thor" Giron +% +% Contributors: +% - Mathieu Mahé +% - Gaëtan JUVIN +% - Unknown for now +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +% This class provides a layout for teaching material at 42. +% +% This class is organized this way : +% +% I - Documentation +% 1. Incompatibilites +% II - General LaTeX boilerplate +% 1. Definition +% 2. Class options and parent class +% 3. Imports +% III - Lengths and color redefinitions +% 1. Lenghts +% 2. Colors +% 3. Hyperlinks +% 4. Listings +% 5. Page layout +% 6. Roman numerals for chapters +% IV - Frontpage customization +% 1. Custom fields +% 2. Redefinition of \maketitle +% 3. Exercice number +% V - Custom helper commands +% 1. Hint/warn +% 2. Lisibility helper +% 3. Exercise headers +% 4. Reproduction from man + +%% +%% I - Documentation +%% + +%% I.1 - Incompatibilities + +% Package ulem: +% The package ulem has a lot of oddities. Using it is not always a +% good idea. If you really want to do so, you should import it with +% the [normalem] option, as such : +% \usepackage[normalem]{ulem} +% Otherwise, it overrides \emph to underline the emphasized text. So +% far so good, but underlined text is typesetted in a box, which means +% that linebreaks don't happen automatically. Since \abstract (among +% others) uses \emph, the abstract is unreadable by default. +% Please read thoroughly ulem's doc before using it. +% See also: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=underline + +%% +%% II - General LaTeX boilerplate +%% + +%% II.1 - Definition + +\NeedsTeXFormat{LaTeX2e}[1995/12/01] +\ProvidesClass{42-hy}[2020/04/12 v2.2 + LaTeX class for 42-themed documents] + +%% II.2 - Class options and parent class + +\newcommand{\summarytitle}{Ամփոփում}% + +\DeclareOption*{% + \PassOptionsToClass{\CurrentOption}{report} +} + +\ProcessOptions\relax +\LoadClass[a4paper,12pt,onecolumn]{report} + +%% II.3 - Imports + +\usepackage[top=1in,bottom=1in,left=1in,right=1in]{geometry} +\usepackage{graphicx} +\usepackage{url} +\usepackage{fancyhdr} +\usepackage{array} +\usepackage[table]{xcolor} +\usepackage[utf8]{inputenc} +\usepackage[T1]{fontenc} +\usepackage{lmodern} +\usepackage{listings} +\usepackage{tabularx} +\usepackage{textcomp} +\usepackage{color} +\usepackage{hyperref} +\usepackage{fancybox} +\usepackage{float} +\usepackage{atbeginend} % provided locally : atbeginend.sty +\usepackage{tocloft} % provided locally : tocloft.sty +\usepackage{multirow} % provided locally : multirow.sty +\usepackage[english]{babel} +\usepackage{minted} % provided locally : minted.sty +% Minted requires the Python "Pygments" librairy (http://pygments.org/). +% Pygments can be easily installed with the "easy_install" paquet manager +% from the "python-setuptools" paquet (sudo easy_install Pygments). +\usepackage{pifont,mdframed} +\usepackage{wallpaper} + + +%%%%%%%%% for smooth Armenian :) %%%%%%%%%% + +% NEEDS FIXING + +%\usepackage{fontspec} +%\setmainfont{DejaVu Serif} + +\addto\captionsenglish{\renewcommand{\chaptername}{Գլուխ}} +\addto\captionsenglish{\renewcommand{\contentsname}{Ցանկ}} + +%%%%%%%% End of smooth Armenian + + +%% III - Lengths and color redefinitions + +%% III.1 - Lengths + +\AfterBegin{enumerate}{ + \itemsep10pt% +} +\AfterBegin{itemize}{ + \itemsep5pt% + \renewcommand{\labelitemi}{$\bullet$}% + \renewcommand{\labelitemii}{$\circ$}% +} + +\BeforeBegin{enumerate}{\vspace{15pt}} +\AfterEnd{enumerate}{\vspace{15pt}} + +\BeforeBegin{itemize}{\vspace{15pt}} +\AfterEnd{itemize}{\vspace{15pt}} + +\BeforeBegin{lstlisting}{\vspace{15pt}} +\AfterEnd{lstlisting}{\vspace{15pt}} + +\BeforeBegin{tabularx}{\vspace{15pt}} +\AfterEnd{tabularx}{\vspace{15pt}} + +%% III.2 - Colors + +\definecolor{nicergreen}{rgb}{0,0.502,0} +\definecolor{nicerblue}{rgb}{0,0.302,1} +\definecolor{nicerorange}{rgb}{1,0.502,0} +\definecolor{nicergrey}{rgb}{0.502,0.502,0.502} +\definecolor{nicerred}{rgb}{0.626,0,0} +\definecolor{hintbg}{rgb}{1.0,1.0,0.75} +\definecolor{warnbg}{rgb}{1.0,0.75,0.75} +\definecolor{infobg}{rgb}{0.75,0.75,1.0} +\definecolor{bibliotechbg}{RGB}{239,253,255} +\definecolor{lightgrey}{rgb}{0.95,0.95,0.95} +\definecolor{darkgrey}{rgb}{0.1,0.1,0.1} +\definecolor{assholeblack}{rgb}{0,0,0} + +%% III.3 - Hyperlinks + +\hypersetup +{ + colorlinks, +% citecolor=black, % +% filecolor=black, % + linkcolor=black, % black links + urlcolor=blue % blue URLs +} + +%% III.4 - Listings + +\lstset +{ + backgroundcolor=\color{gray!15}, + basicstyle=\small\ttfamily, + breaklines=true, + columns=fullflexible, + frame=lines, + tabsize=4, + numbers=none, %numbers=left, + numberstyle=\scriptsize\ttfamily, + numbersep=5pt, + showspaces=false, + showstringspaces=false, + showtabs=false, + breaklines=true, + upquote=true, + float +} + +%% III.5 - Page layout + +\makeatletter +\pagestyle{fancy} +\lhead{\@title} +\rhead{\@subtitle} +\cfoot{\thepage} +\makeatother + +%% III.6 - Roman chapter style + +% custom sections style + +\renewcommand{\thechapter}{\Roman{chapter}} +\renewcommand{\chaptername}{Գլուխ} + +% Using roman numerals makes the TOC section/subsection numbers +% overflow on the right. This adds some margin to avoid that kind of +% problems. (requires \usepackage{tocloft}) +\setlength{\cftchapnumwidth}{1.5cm} +\setlength{\cftsecnumwidth}{1.5cm} +\setlength{\cftsubsecnumwidth}{1.3cm} +\setlength{\cftsubsubsecnumwidth}{1.6cm} +\setlength{\cftaftertoctitleskip}{0.5cm} + +%% IV - Frontpage customization + +%% IV.1 - Custom fields +\makeatletter +\newcommand{\website}[1]{\def \@website {#1}} +\website{} + +\newcommand{\subtitle}[1]{\def \@subtitle {#1}} +\subtitle{} + +\newcommand{\schoollogo}[1]{\def \@schoollogo {#1}} +\schoollogo{42_logo.pdf} + +\newcommand{\summary}[1]{\def \@summary {#1}} +\summary{} + +\edef\@authors{} +\newcommand{\member}[2]{% + \protected@edef\@authors{\@authors #1 \protect\url{#2}\\} + \author{\@authors} +} +\author{} + +%% IV.2 - Redefine \maketitle + +\makeatletter +\def \maketitle { + \begin{titlepage} + \begin{center} + %\begin{figure}[t] + \includegraphics[height=8cm]{\@schoollogo} + %\end{figure} + \vskip 5em + {\huge \@title} + \vskip 2em + {\LARGE \@subtitle} + \vskip 4em + \end{center} + \begin{center} + \@author + \end{center} + \vskip 5em + \begin{center} + \emph{\summarytitle : \@summary} + \end{center} + \end{titlepage} +} +\makeatother + +\TileWallPaper{\paperwidth}{\paperheight}{back} +%% IV.3 - Exercice number + +\newcounter{exerciceCounter} +\newcommand*{\exercicenumber}{ + \ifnum\value{exerciceCounter}<10 0\fi + \arabic{exerciceCounter} +} + +\newcommand*{\startexercices}{ + \setcounter{exerciceCounter}{0} +} + +\newcommand*{\nextexercice}{ + \stepcounter{exerciceCounter} +} + +\newcounter{itemizeCounter} +\setcounter{itemizeCounter}{0} +\BeforeBegin{itemize}{ + \addtocounter{itemizeCounter}{1} +} + +\AfterEnd{itemize}{ + \addtocounter{itemizeCounter}{-1} + \ifnum\value{itemizeCounter} = 0 + \stepcounter{exerciceCounter} + \fi +} + +%% V - Custom helper commands + +%% V.1 - Hint/Warn + +% hint command + +\newcommand{\kbox}[3] +{ + \vskip 15pt + \noindent + \colorbox{#1} + { + \begin{tabular*}{0.97\textwidth}{m{4em}m{0.8\textwidth}} + \includegraphics[width=4em]{#2} + & {\footnotesize #3}\\ + \end{tabular*} + } + \vskip 15pt +} + +\newcommand{\hint}[1]{\kbox{hintbg}{helphint.pdf}{#1}} +\newcommand{\warn}[1]{\kbox{warnbg}{warn.pdf}{#1}} +\newcommand{\info}[1]{\kbox{infobg}{info.pdf}{#1}} + +%% V.2 Lisibility helper + +\makeatletter +\newcommand{\mso}[1]{ + \ttfamily #1 \normalfont +} + +%% V.3 Exercise headers + +\makeatletter +\newcommand{\turnindir}[1]{\def \@turnindir {#1}} +\newcommand{\daypiscine}[1]{\def \@daypiscine {#1}} +\newcommand{\extitle}[1]{\def \@extitle {#1}} +\newcommand{\exnumber}[1]{\def \@exnumber {#1}} +\newcommand{\exscore}[1]{\def \@exscore {#1}} +\newcommand{\exflags}[1][-W -Wall -Werror]{\def \@exflags {#1}} +\newcommand{\excompil}[1][gcc]{\def \@excompil {#1}} +\newcommand{\exrules}[1][n/a]{\def \@exrules {#1}} +\newcommand{\exfiles}[1]{\def \@exfiles {#1}} +\newcommand{\exnotes}[1][n/a]{\def \@exnotes {#1}} +\newcommand{\exauthorize}[1]{\def \@exauthorize {#1}} +\newcommand{\exforbidden}[1]{\def \@exforbidden {#1}} +\newcommand{\exmake}[1][No]{\def \@exmake {#1}} + +% Default values +\turnindir{} +\daypiscine{} +\extitle{} +\exnumber{} +\exscore{} +\exflags{} +\excompil{} +\exrules{} +\exfiles{} +\exnotes{} +\exauthorize{None} +\exforbidden{None} +\exmake{} + +%Header pour exercices sans rien a "rendre" +\newcommand{\makeheaderbasic} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Առաջադրանք : \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + +%% \multicolumn{4}{|>{\raggedright}m{15cm}|} +%% {\small Notes : \ttfamily \@exnotes } +%% \\ \hline +\end{tabularx} +%% \exnotes +\exrules +\exmake +%\exauthorize +\exforbidden{None} +\extitle{} +\exnumber{} +} + +%Header pour exercices sans code mais fichiers a rendre +\newcommand{\makeheaderfiles} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Առաջադրանք \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Հանձնման պահոց՝ \ttfamily + $ex\@exnumber/$ } + \\ \hline + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Հանձնվելիք ֆայլեր՝ \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Թույլատրված ֆունկցիաներ՝ \ttfamily \@exauthorize } + \\ \hline + +%% \multicolumn{4}{|>{\raggedright}m{15cm}|} +%% {\small Notes : \ttfamily \@exnotes } +%% \\ \hline +\end{tabularx} +%% \exnotes +\exrules +\exmake +\exauthorize{None} +\exforbidden{None} +\extitle{} +\exnumber{} +} + +%Header for exercices without turn in repository +\newcommand{\makeheaderfilesnodirectory} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Առաջադրանք : \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Հանձնվելիք ֆայլեր՝ \ttfamily \@exauthorize } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Թույլատրված ֆունկցիաներ՝ \ttfamily \@exnotes } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Նշում՝ \ttfamily \@exnotes } + \\ \hline +\end{tabularx} +\exnotes +\exrules +\exmake +\exauthorize{None} +\exforbidden{None} +\extitle{} +\exnumber{} +} + +%Header pour exercices sans code mais fichiers a rendre +\newcommand{\makeheaderfilesforbidden} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Առաջադրանք \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Հանձնման պահոց՝ \ttfamily + $ex\@exnumber/$ } + \\ \hline + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Հանձնվելիք ֆայլեր՝ \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Արգելված ֆունկցիաներ՝ \ttfamily \@exforbidden } + \\ \hline + +%% \multicolumn{4}{|>{\raggedright}m{15cm}|} +%% {\small Remarks : \ttfamily \@exnotes } +%% \\ \hline +\end{tabularx} +%% \exnotes +\exrules +\exmake +\exauthorize{None} +\exforbidden{None} +\extitle{} +\exnumber{} +} + +%Header pour exercices de code +\newcommand{\makeheadercode} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Առաջադրանք՝ \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} + %% {\scriptsize Score : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Հանձնման պահոց՝ \ttfamily + $ex\@exnumber/$ } + \\ \hline + + \multicolumn{2}{|>{\raggedright}m{7.5cm}} + {\small Կազմարկիչ \ttfamily \@excompil } & + \multicolumn{2}{|>{\raggedright}m{7.5cm}|} + {\small Կազրմարկման դրոշակներ՝ + \ttfamily \@exflags } + \\ \hline + + \multicolumn{2}{|>{\raggedright}m{7.52cm}} + {\small Ստեղծել ֆայլ \ttfamily{\@exmake}} & + \multicolumn{2}{|>{\raggedright}m{7.5cm}|} + {Ֆայլերի ստեղծման կանոններ՝ \ttfamily \@exrules } \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Հանձնվելիք ֆայլեր՝ \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Նշումներ՝ \ttfamily \@exnotes } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Արգելված ֆունկցիաներ՝ \ttfamily \@exforbidden } + \\ \hline +\end{tabularx} +\exnotes +\exrules +\exmake +\exforbidden{None} +\extitle{} +\exnumber{} +} + + +\newcommand{\ftname}[1]{\def \@ftname {#1}} +\newcommand{\ftprototype}[1]{\def \@ftprototype {#1}} +\newcommand{\ftdesc}[1]{\def \@ftdesc {#1}} +\newcommand{\ftparams}[1]{\def \@ftparams {#1}} +\newcommand{\ftret}[1]{\def \@ftret {#1}} +\newcommand{\ftfuncts}[1]{\def \@ftfuncts {#1}} +\newcommand{\ftturnin}[1]{\def \@ftturnin {#1}} +\newcommand{\ftmakefile}[1]{\def \@ftmakefile {#1}} +\newcommand{\ftlibft}[1]{\def \@ftlibft {#1}} +\newcommand{\ftcompil}[1]{\def \@ftcompil {#1}} + +\ftname{} +\ftprototype{} +\ftdesc{} +\ftparams{} +\ftret{} +\ftfuncts{} +\ftturnin{} +\ftmakefile{} +\ftlibft{} +\ftcompil{} + + +\newcolumntype{s}{>{\hsize=.5\hsize}X} +\newcolumntype{b}{>{\hsize=1.5\hsize}X} +\newcommand{\makeheaderfct} +{ + \noindent + + \begin{tabularx}{\textwidth}{| s | b |} \hline + + \textbf{Ֆունկցիայի անուն} & \texttt{\@ftname} \\ \hline + \textbf{Նախատիպ} & \texttt{\@ftprototype} \\ \hline + \textbf{Հանձնվելիք ֆայլեր} & \texttt{\@ftturnin} \\ \hline + \textbf{Պարամետրեր} & \texttt{\@ftparams} \\ \hline + \textbf{Վերադարձի արժեք} & \texttt{\@ftret} \\ \hline + \textbf{Արտաքին ֆունկցիաներ} & \texttt{\@ftfuncts} \\ \hline + \textbf{Նկարագրություն} & \texttt{\@ftdesc} \\ \hline + +\end{tabularx} +} + +\newcommand{\makeheaderlib} +{ + \noindent + + \begin{tabularx}{\textwidth}{| s | b |} \hline + + \textbf{Ծրագրի անուն} & \texttt{\@ftname} \\ \hline + \textbf{Հանձնվելիք ֆայլեր} & \texttt{\@ftturnin} \\ \hline + \textbf{Ստեղծել ֆայլ} & \texttt{\@ftmakefile} \\ \hline + \textbf{Արտաքին ֆունկցիաներ} & \texttt{\@ftfuncts} \\ \hline + \textbf{Libft authorized} & \texttt{\@ftlibft} \\ \hline + \textbf{Նկարագրություն} & \texttt{\@ftdesc} \\ \hline + +\end{tabularx} +} + +\newcommand{\makeheaderprg} +{ + \noindent + + \begin{tabularx}{\textwidth}{| s | b |} \hline + + \textbf{Ծրագրի անուն} & \texttt{\@ftname} \\ \hline + \textbf{Հանձնվելիք ֆայլեր} & \texttt{\@ftturnin} \\ \hline + \textbf{Ստեղծել ֆայլ} & \texttt{\@ftmakefile} \\ \hline + \textbf{Արգումենտներ} & \texttt{\@ftparams} \\ \hline + \textbf{Արտաքին ֆունկցիաներ} & \texttt{\@ftfuncts} \\ \hline + \textbf{Libft authorized} & \texttt{\@ftlibft} \\ \hline + \textbf{Նկարագրություն} & \texttt{\@ftdesc} \\ \hline + +\end{tabularx} +} + + +\newcommand{\exmandatory}{Պարտադիր առաջադրանք} +\newcommand{\exretrovalid}{Retrovalidated exercise} +\newcommand{\exoptional}{Optional exercise} + +\newcommand{\exercice}{Առաջադրանք} + +%% V.4 Reproduction from man +\newcommand{\reproductionfromman}[1]{Վերարտադրել \texttt{#1} (man #1) ֆունկցիայի վարքը։} + +%% VI - Syntactic highlights + + +%% Styles: +%% ~~~~~~~ +%% * monokai: +%% This style mimics the Monokai color scheme. +%% * manni: +%% A colorful style, inspired by the terminal highlighting style. +%% * rrt: +%% Minimalistic ``rrt'' theme, based on Zap and Emacs defaults. +%% * perldoc: +%% Style similar to the style used in the perldoc code blocks. +%% * borland: +%% Style similar to the style used in the borland IDEs. +%% * colorful: +%% A colorful style, inspired by CodeRay. +%% * default: +%% The default style (inspired by Emacs 22). +%% * murphy: +%% Murphy's style from CodeRay. +%% * vs: +%% +%% * trac: +%% Port of the default trac highlighter design. +%% * tango: +%% The Crunchy default Style inspired from the color palette from the Tango Icon Theme Guidelines. +%% * fruity: +%% Pygments version of the ``native'' vim theme. +%% * autumn: +%% A colorful style, inspired by the terminal highlighting style. +%% * bw: +%% +%% * emacs: +%% The default style (inspired by Emacs 22). +%% * vim: +%% Styles somewhat like vim 7.0 +%% * pastie: +%% Style similar to the pastie default style. +%% * friendly: +%% A modern style based on the VIM pyte theme. +%% * native: +%% Pygments version of the ``native'' vim theme. + + + +%\usemintedstyle{monokai} +%\usemintedstyle{manni} +%\usemintedstyle{rrt} +%\usemintedstyle{perldoc} +%\usemintedstyle{borland} +%\usemintedstyle{colorful} +%\usemintedstyle{default} +%\usemintedstyle{murphy} +%\usemintedstyle{vs} +%\usemintedstyle{trac} +%\usemintedstyle{tango} +%\usemintedstyle{fruity} +%\usemintedstyle{autumn} +%\usemintedstyle{bw} +%\usemintedstyle{emacs} +%\usemintedstyle{vim} +%\usemintedstyle{pastie} +%\usemintedstyle{friendly} +%\usemintedstyle{native} + +\makeatletter +\newenvironment{42ccode}{% + \VerbatimEnvironment + \usemintedstyle{emacs} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{c} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42phpcode}{% + \VerbatimEnvironment + \usemintedstyle{emacs} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{html+php} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42jscode}{% + \VerbatimEnvironment + \usemintedstyle{emacs} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{js} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\definecolor{darcula-back}{RGB}{35, 37, 37} + +\makeatletter +\newenvironment{42javacode}{% + \VerbatimEnvironment + \usemintedstyle{monokai} + \minted@resetoptions + \definecolor{dark}{RGB}{35, 37, 37} + \setkeys{minted@opt}{bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{java} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42xmlcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{xml} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42yamlcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{yaml} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42cppcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{c++} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + + +\makeatletter +\newenvironment{42ocamlcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{ocaml} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + + +\makeatletter +\newenvironment{42asmcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{nasm} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\lstnewenvironment{42console} { + \lstset { + extendedchars=true, + literate={✓}{{\checkmark}}1, + basicstyle=\color{lightgrey}\scriptsize\ttfamily, + backgroundcolor=\color{assholeblack}, + breaklines=true, + numberstyle=\scriptsize, + columns=flexible, + keepspaces=false, + } +}{} + +\newenvironment{42warning} + { + \vspace*{1\baselineskip} + \par\begin{mdframed}[linewidth=2pt,linecolor=red]% + \begin{list}{}{\leftmargin=1cm + \labelwidth=\leftmargin}\item[\Large\ding{43}]} + {\end{list}\end{mdframed}\par \vspace*{1\baselineskip}} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% 42.cls +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% Authors: +% - Maxime "zaz" Montinet +% - David "Thor" Giron +% +% Contributors: +% - Mathieu Mahé +% - Gaëtan JUVIN +% - Unknown for now +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +% This class provides a layout for teaching material at 42. +% +% This class is organized this way : +% +% I - Documentation +% 1. Incompatibilites +% II - General LaTeX boilerplate +% 1. Definition +% 2. Class options and parent class +% 3. Imports +% III - Lengths and color redefinitions +% 1. Lenghts +% 2. Colors +% 3. Hyperlinks +% 4. Listings +% 5. Page layout +% 6. Roman numerals for chapters +% IV - Frontpage customization +% 1. Custom fields +% 2. Redefinition of \maketitle +% 3. Exercice number +% V - Custom helper commands +% 1. Hint/warn +% 2. Lisibility helper +% 3. Exercise headers +% 4. Reproduction from man + +%% +%% I - Documentation +%% + +%% I.1 - Incompatibilities + +% Package ulem: +% The package ulem has a lot of oddities. Using it is not always a +% good idea. If you really want to do so, you should import it with +% the [normalem] option, as such : +% \usepackage[normalem]{ulem} +% Otherwise, it overrides \emph to underline the emphasized text. So +% far so good, but underlined text is typesetted in a box, which means +% that linebreaks don't happen automatically. Since \abstract (among +% others) uses \emph, the abstract is unreadable by default. +% Please read thoroughly ulem's doc before using it. +% See also: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=underline + +%% +%% II - General LaTeX boilerplate +%% + +%% II.1 - Definition + +\NeedsTeXFormat{LaTeX2e}[1995/12/01] +\ProvidesClass{42-hy}[2020/04/12 v2.2 + LaTeX class for 42-themed documents] + +%% II.2 - Class options and parent class + +\newcommand{\summarytitle}{Ամփոփում}% + +\DeclareOption*{% + \PassOptionsToClass{\CurrentOption}{report} +} + +\ProcessOptions\relax +\LoadClass[a4paper,12pt,onecolumn]{report} + +%% II.3 - Imports + +\usepackage[top=1in,bottom=1in,left=1in,right=1in]{geometry} +\usepackage{graphicx} +\usepackage{url} +\usepackage{fancyhdr} +\usepackage{array} +\usepackage[table]{xcolor} +\usepackage[utf8]{inputenc} +\usepackage[T1]{fontenc} +\usepackage{lmodern} +\usepackage{listings} +\usepackage{tabularx} +\usepackage{textcomp} +\usepackage{color} +\usepackage{hyperref} +\usepackage{fancybox} +\usepackage{float} +\usepackage{atbeginend} % provided locally : atbeginend.sty +\usepackage{tocloft} % provided locally : tocloft.sty +\usepackage{multirow} % provided locally : multirow.sty +\usepackage[english]{babel} +\usepackage{minted} % provided locally : minted.sty +% Minted requires the Python "Pygments" librairy (http://pygments.org/). +% Pygments can be easily installed with the "easy_install" paquet manager +% from the "python-setuptools" paquet (sudo easy_install Pygments). +\usepackage{pifont,mdframed} +\usepackage{wallpaper} + + +%%%%%%%%% for smooth Armenian :) %%%%%%%%%% +\usepackage{fontspec} +\setmainfont{DejaVu Serif} + +\addto\captionsenglish{\renewcommand{\chaptername}{Գլուխ}} +\addto\captionsenglish{\renewcommand{\contentsname}{Ցանկ}} + +%%%%%%%% End of smooth Armenian + + +%% III - Lengths and color redefinitions + +%% III.1 - Lengths + +\AfterBegin{enumerate}{ + \itemsep10pt% +} +\AfterBegin{itemize}{ + \itemsep5pt% + \renewcommand{\labelitemi}{$\bullet$}% + \renewcommand{\labelitemii}{$\circ$}% +} + +\BeforeBegin{enumerate}{\vspace{15pt}} +\AfterEnd{enumerate}{\vspace{15pt}} + +\BeforeBegin{itemize}{\vspace{15pt}} +\AfterEnd{itemize}{\vspace{15pt}} + +\BeforeBegin{lstlisting}{\vspace{15pt}} +\AfterEnd{lstlisting}{\vspace{15pt}} + +\BeforeBegin{tabularx}{\vspace{15pt}} +\AfterEnd{tabularx}{\vspace{15pt}} + +%% III.2 - Colors + +\definecolor{nicergreen}{rgb}{0,0.502,0} +\definecolor{nicerblue}{rgb}{0,0.302,1} +\definecolor{nicerorange}{rgb}{1,0.502,0} +\definecolor{nicergrey}{rgb}{0.502,0.502,0.502} +\definecolor{nicerred}{rgb}{0.626,0,0} +\definecolor{hintbg}{rgb}{1.0,1.0,0.75} +\definecolor{warnbg}{rgb}{1.0,0.75,0.75} +\definecolor{infobg}{rgb}{0.75,0.75,1.0} +\definecolor{bibliotechbg}{RGB}{239,253,255} +\definecolor{lightgrey}{rgb}{0.95,0.95,0.95} +\definecolor{darkgrey}{rgb}{0.1,0.1,0.1} +\definecolor{assholeblack}{rgb}{0,0,0} + +%% III.3 - Hyperlinks + +\hypersetup +{ + colorlinks, +% citecolor=black, % +% filecolor=black, % + linkcolor=black, % black links + urlcolor=blue % blue URLs +} + +%% III.4 - Listings + +\lstset +{ + backgroundcolor=\color{gray!15}, + basicstyle=\small\ttfamily, + breaklines=true, + columns=fullflexible, + frame=lines, + tabsize=4, + numbers=none, %numbers=left, + numberstyle=\scriptsize\ttfamily, + numbersep=5pt, + showspaces=false, + showstringspaces=false, + showtabs=false, + breaklines=true, + upquote=true, + float +} + +%% III.5 - Page layout + +\makeatletter +\pagestyle{fancy} +\lhead{\@title} +\rhead{\@subtitle} +\cfoot{\thepage} +\makeatother + +%% III.6 - Roman chapter style + +% custom sections style + +\renewcommand{\thechapter}{\Roman{chapter}} +\renewcommand{\chaptername}{Գլուխ} + +% Using roman numerals makes the TOC section/subsection numbers +% overflow on the right. This adds some margin to avoid that kind of +% problems. (requires \usepackage{tocloft}) +\setlength{\cftchapnumwidth}{1.5cm} +\setlength{\cftsecnumwidth}{1.5cm} +\setlength{\cftsubsecnumwidth}{1.3cm} +\setlength{\cftsubsubsecnumwidth}{1.6cm} +\setlength{\cftaftertoctitleskip}{0.5cm} + +%% IV - Frontpage customization + +%% IV.1 - Custom fields +\makeatletter +\newcommand{\website}[1]{\def \@website {#1}} +\website{} + +\newcommand{\subtitle}[1]{\def \@subtitle {#1}} +\subtitle{} + +\newcommand{\schoollogo}[1]{\def \@schoollogo {#1}} +\schoollogo{42_logo.pdf} + +\newcommand{\summary}[1]{\def \@summary {#1}} +\summary{} + +\edef\@authors{} +\newcommand{\member}[2]{% + \protected@edef\@authors{\@authors #1 \protect\url{#2}\\} + \author{\@authors} +} +\author{} + +%% IV.2 - Redefine \maketitle + +\makeatletter +\def \maketitle { + \begin{titlepage} + \begin{center} + %\begin{figure}[t] + \includegraphics[height=8cm]{\@schoollogo} + %\end{figure} + \vskip 5em + {\huge \@title} + \vskip 2em + {\LARGE \@subtitle} + \vskip 4em + \end{center} + \begin{center} + \@author + \end{center} + \vskip 5em + \begin{center} + \emph{\summarytitle : \@summary} + \end{center} + \end{titlepage} +} +\makeatother + +\TileWallPaper{\paperwidth}{\paperheight}{back} +%% IV.3 - Exercice number + +\newcounter{exerciceCounter} +\newcommand*{\exercicenumber}{ + \ifnum\value{exerciceCounter}<10 0\fi + \arabic{exerciceCounter} +} + +\newcommand*{\startexercices}{ + \setcounter{exerciceCounter}{0} +} + +\newcommand*{\nextexercice}{ + \stepcounter{exerciceCounter} +} + +\newcounter{itemizeCounter} +\setcounter{itemizeCounter}{0} +\BeforeBegin{itemize}{ + \addtocounter{itemizeCounter}{1} +} + +\AfterEnd{itemize}{ + \addtocounter{itemizeCounter}{-1} + \ifnum\value{itemizeCounter} = 0 + \stepcounter{exerciceCounter} + \fi +} + +%% V - Custom helper commands + +%% V.1 - Hint/Warn + +% hint command + +\newcommand{\kbox}[3] +{ + \vskip 15pt + \noindent + \colorbox{#1} + { + \begin{tabular*}{0.97\textwidth}{m{4em}m{0.8\textwidth}} + \includegraphics[width=4em]{#2} + & {\footnotesize #3}\\ + \end{tabular*} + } + \vskip 15pt +} + +\newcommand{\hint}[1]{\kbox{hintbg}{helphint.pdf}{#1}} +\newcommand{\warn}[1]{\kbox{warnbg}{warn.pdf}{#1}} +\newcommand{\info}[1]{\kbox{infobg}{info.pdf}{#1}} + +%% V.2 Lisibility helper + +\makeatletter +\newcommand{\mso}[1]{ + \ttfamily #1 \normalfont +} + +%% V.3 Exercise headers + +\makeatletter +\newcommand{\turnindir}[1]{\def \@turnindir {#1}} +\newcommand{\daypiscine}[1]{\def \@daypiscine {#1}} +\newcommand{\extitle}[1]{\def \@extitle {#1}} +\newcommand{\exnumber}[1]{\def \@exnumber {#1}} +\newcommand{\exscore}[1]{\def \@exscore {#1}} +\newcommand{\exflags}[1][-W -Wall -Werror]{\def \@exflags {#1}} +\newcommand{\excompil}[1][gcc]{\def \@excompil {#1}} +\newcommand{\exrules}[1][n/a]{\def \@exrules {#1}} +\newcommand{\exfiles}[1]{\def \@exfiles {#1}} +\newcommand{\exnotes}[1][n/a]{\def \@exnotes {#1}} +\newcommand{\exauthorize}[1]{\def \@exauthorize {#1}} +\newcommand{\exforbidden}[1]{\def \@exforbidden {#1}} +\newcommand{\exmake}[1][No]{\def \@exmake {#1}} + +% Default values +\turnindir{} +\daypiscine{} +\extitle{} +\exnumber{} +\exscore{} +\exflags{} +\excompil{} +\exrules{} +\exfiles{} +\exnotes{} +\exauthorize{None} +\exforbidden{None} +\exmake{} + +%Header pour exercices sans rien a "rendre" +\newcommand{\makeheaderbasic} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Առաջադրանք : \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + +%% \multicolumn{4}{|>{\raggedright}m{15cm}|} +%% {\small Notes : \ttfamily \@exnotes } +%% \\ \hline +\end{tabularx} +%% \exnotes +\exrules +\exmake +%\exauthorize +\exforbidden{None} +\extitle{} +\exnumber{} +} + +%Header pour exercices sans code mais fichiers a rendre +\newcommand{\makeheaderfiles} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Առաջադրանք \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Հանձնման պահոց՝ \ttfamily + $ex\@exnumber/$ } + \\ \hline + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Հանձնվելիք ֆայլեր՝ \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Թույլատրված ֆունկցիաներ՝ \ttfamily \@exauthorize } + \\ \hline + +%% \multicolumn{4}{|>{\raggedright}m{15cm}|} +%% {\small Notes : \ttfamily \@exnotes } +%% \\ \hline +\end{tabularx} +%% \exnotes +\exrules +\exmake +\exauthorize{None} +\exforbidden{None} +\extitle{} +\exnumber{} +} + +%Header for exercices without turn in repository +\newcommand{\makeheaderfilesnodirectory} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Առաջադրանք : \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Հանձնվելիք ֆայլեր՝ \ttfamily \@exauthorize } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Թույլատրված ֆունկցիաներ՝ \ttfamily \@exnotes } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Նշում՝ \ttfamily \@exnotes } + \\ \hline +\end{tabularx} +\exnotes +\exrules +\exmake +\exauthorize{None} +\exforbidden{None} +\extitle{} +\exnumber{} +} + +%Header pour exercices sans code mais fichiers a rendre +\newcommand{\makeheaderfilesforbidden} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Առաջադրանք \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Հանձնման պահոց՝ \ttfamily + $ex\@exnumber/$ } + \\ \hline + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Հանձնվելիք ֆայլեր՝ \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Արգելված ֆունկցիաներ՝ \ttfamily \@exforbidden } + \\ \hline + +%% \multicolumn{4}{|>{\raggedright}m{15cm}|} +%% {\small Remarks : \ttfamily \@exnotes } +%% \\ \hline +\end{tabularx} +%% \exnotes +\exrules +\exmake +\exauthorize{None} +\exforbidden{None} +\extitle{} +\exnumber{} +} + +%Header pour exercices de code +\newcommand{\makeheadercode} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Առաջադրանք՝ \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} + %% {\scriptsize Score : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Հանձնման պահոց՝ \ttfamily + $ex\@exnumber/$ } + \\ \hline + + \multicolumn{2}{|>{\raggedright}m{7.5cm}} + {\small Կազմարկիչ \ttfamily \@excompil } & + \multicolumn{2}{|>{\raggedright}m{7.5cm}|} + {\small Կազրմարկման դրոշակներ՝ + \ttfamily \@exflags } + \\ \hline + + \multicolumn{2}{|>{\raggedright}m{7.52cm}} + {\small Ստեղծել ֆայլ \ttfamily{\@exmake}} & + \multicolumn{2}{|>{\raggedright}m{7.5cm}|} + {Ֆայլերի ստեղծման կանոններ՝ \ttfamily \@exrules } \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Հանձնվելիք ֆայլեր՝ \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Նշումներ՝ \ttfamily \@exnotes } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Արգելված ֆունկցիաներ՝ \ttfamily \@exforbidden } + \\ \hline +\end{tabularx} +\exnotes +\exrules +\exmake +\exforbidden{None} +\extitle{} +\exnumber{} +} + + +\newcommand{\ftname}[1]{\def \@ftname {#1}} +\newcommand{\ftprototype}[1]{\def \@ftprototype {#1}} +\newcommand{\ftdesc}[1]{\def \@ftdesc {#1}} +\newcommand{\ftparams}[1]{\def \@ftparams {#1}} +\newcommand{\ftret}[1]{\def \@ftret {#1}} +\newcommand{\ftfuncts}[1]{\def \@ftfuncts {#1}} +\newcommand{\ftturnin}[1]{\def \@ftturnin {#1}} +\newcommand{\ftmakefile}[1]{\def \@ftmakefile {#1}} +\newcommand{\ftlibft}[1]{\def \@ftlibft {#1}} +\newcommand{\ftcompil}[1]{\def \@ftcompil {#1}} + +\ftname{} +\ftprototype{} +\ftdesc{} +\ftparams{} +\ftret{} +\ftfuncts{} +\ftturnin{} +\ftmakefile{} +\ftlibft{} +\ftcompil{} + + +\newcolumntype{s}{>{\hsize=.5\hsize}X} +\newcolumntype{b}{>{\hsize=1.5\hsize}X} +\newcommand{\makeheaderfct} +{ + \noindent + + \begin{tabularx}{\textwidth}{| s | b |} \hline + + \textbf{Ֆունկցիայի անուն} & \texttt{\@ftname} \\ \hline + \textbf{Նախատիպ} & \texttt{\@ftprototype} \\ \hline + \textbf{Հանձնվելիք ֆայլեր} & \texttt{\@ftturnin} \\ \hline + \textbf{Պարամետրեր} & \texttt{\@ftparams} \\ \hline + \textbf{Վերադարձի արժեք} & \texttt{\@ftret} \\ \hline + \textbf{Արտաքին ֆունկցիաներ} & \texttt{\@ftfuncts} \\ \hline + \textbf{Նկարագրություն} & \texttt{\@ftdesc} \\ \hline + +\end{tabularx} +} + +\newcommand{\makeheaderlib} +{ + \noindent + + \begin{tabularx}{\textwidth}{| s | b |} \hline + + \textbf{Ծրագրի անուն} & \texttt{\@ftname} \\ \hline + \textbf{Հանձնվելիք ֆայլեր} & \texttt{\@ftturnin} \\ \hline + \textbf{Ստեղծել ֆայլ} & \texttt{\@ftmakefile} \\ \hline + \textbf{Արտաքին ֆունկցիաներ} & \texttt{\@ftfuncts} \\ \hline + \textbf{Libft authorized} & \texttt{\@ftlibft} \\ \hline + \textbf{Նկարագրություն} & \texttt{\@ftdesc} \\ \hline + +\end{tabularx} +} + +\newcommand{\makeheaderprg} +{ + \noindent + + \begin{tabularx}{\textwidth}{| s | b |} \hline + + \textbf{Ծրագրի անուն} & \texttt{\@ftname} \\ \hline + \textbf{Հանձնվելիք ֆայլեր} & \texttt{\@ftturnin} \\ \hline + \textbf{Ստեղծել ֆայլ} & \texttt{\@ftmakefile} \\ \hline + \textbf{Արգումենտներ} & \texttt{\@ftparams} \\ \hline + \textbf{Արտաքին ֆունկցիաներ} & \texttt{\@ftfuncts} \\ \hline + \textbf{Libft authorized} & \texttt{\@ftlibft} \\ \hline + \textbf{Նկարագրություն} & \texttt{\@ftdesc} \\ \hline + +\end{tabularx} +} + + +\newcommand{\exmandatory}{Պարտադիր առաջադրանք} +\newcommand{\exretrovalid}{Retrovalidated exercise} +\newcommand{\exoptional}{Optional exercise} + +\newcommand{\exercice}{Առաջադրանք} + +%% V.4 Reproduction from man +\newcommand{\reproductionfromman}[1]{Վերարտադրել \texttt{#1} (man #1) ֆունկցիայի վարքը։} + +%% VI - Syntactic highlights + + +%% Styles: +%% ~~~~~~~ +%% * monokai: +%% This style mimics the Monokai color scheme. +%% * manni: +%% A colorful style, inspired by the terminal highlighting style. +%% * rrt: +%% Minimalistic ``rrt'' theme, based on Zap and Emacs defaults. +%% * perldoc: +%% Style similar to the style used in the perldoc code blocks. +%% * borland: +%% Style similar to the style used in the borland IDEs. +%% * colorful: +%% A colorful style, inspired by CodeRay. +%% * default: +%% The default style (inspired by Emacs 22). +%% * murphy: +%% Murphy's style from CodeRay. +%% * vs: +%% +%% * trac: +%% Port of the default trac highlighter design. +%% * tango: +%% The Crunchy default Style inspired from the color palette from the Tango Icon Theme Guidelines. +%% * fruity: +%% Pygments version of the ``native'' vim theme. +%% * autumn: +%% A colorful style, inspired by the terminal highlighting style. +%% * bw: +%% +%% * emacs: +%% The default style (inspired by Emacs 22). +%% * vim: +%% Styles somewhat like vim 7.0 +%% * pastie: +%% Style similar to the pastie default style. +%% * friendly: +%% A modern style based on the VIM pyte theme. +%% * native: +%% Pygments version of the ``native'' vim theme. + + + +%\usemintedstyle{monokai} +%\usemintedstyle{manni} +%\usemintedstyle{rrt} +%\usemintedstyle{perldoc} +%\usemintedstyle{borland} +%\usemintedstyle{colorful} +%\usemintedstyle{default} +%\usemintedstyle{murphy} +%\usemintedstyle{vs} +%\usemintedstyle{trac} +%\usemintedstyle{tango} +%\usemintedstyle{fruity} +%\usemintedstyle{autumn} +%\usemintedstyle{bw} +%\usemintedstyle{emacs} +%\usemintedstyle{vim} +%\usemintedstyle{pastie} +%\usemintedstyle{friendly} +%\usemintedstyle{native} + +\makeatletter +\newenvironment{42ccode}{% + \VerbatimEnvironment + \usemintedstyle{emacs} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{c} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42phpcode}{% + \VerbatimEnvironment + \usemintedstyle{emacs} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{html+php} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42jscode}{% + \VerbatimEnvironment + \usemintedstyle{emacs} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{js} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\definecolor{darcula-back}{RGB}{35, 37, 37} + +\makeatletter +\newenvironment{42javacode}{% + \VerbatimEnvironment + \usemintedstyle{monokai} + \minted@resetoptions + \definecolor{dark}{RGB}{35, 37, 37} + \setkeys{minted@opt}{bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{java} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42xmlcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{xml} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42yamlcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{yaml} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42cppcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{c++} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + + +\makeatletter +\newenvironment{42ocamlcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{ocaml} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + + +\makeatletter +\newenvironment{42asmcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{nasm} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\lstnewenvironment{42console} { + \lstset { + extendedchars=true, + literate={✓}{{\checkmark}}1, + basicstyle=\color{lightgrey}\scriptsize\ttfamily, + backgroundcolor=\color{assholeblack}, + breaklines=true, + numberstyle=\scriptsize, + columns=flexible, + keepspaces=false, + } +}{} + +\newenvironment{42warning} + { + \vspace*{1\baselineskip} + \par\begin{mdframed}[linewidth=2pt,linecolor=red]% + \begin{list}{}{\leftmargin=1cm + \labelwidth=\leftmargin}\item[\Large\ding{43}]} + {\end{list}\end{mdframed}\par \vspace*{1\baselineskip}} diff --git a/resources/latex/42-it.cls b/resources/latex/42-it.cls new file mode 100644 index 00000000..2674760c --- /dev/null +++ b/resources/latex/42-it.cls @@ -0,0 +1,887 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% 42.cls +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% Authors: +% - Maxime "zaz" Montinet +% - David "Thor" Giron +% +% Contributors: +% - Mathieu Mahé +% - Gaëtan JUVIN +% - Unknown for now +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +% This class provides a layout for teaching material at 42. +% +% This class is organized this way : +% +% I - Documentation +% 1. Incompatibilites +% II - General LaTeX boilerplate +% 1. Definition +% 2. Class options and parent class +% 3. Imports +% III - Lengths and color redefinitions +% 1. Lenghts +% 2. Colors +% 3. Hyperlinks +% 4. Listings +% 5. Page layout +% 6. Roman numerals for chapters +% IV - Frontpage customization +% 1. Custom fields +% 2. Redefinition of \maketitle +% 3. Exercice number +% V - Custom helper commands +% 1. Hint/warn +% 2. Lisibility helper +% 3. Exercise headers +% 4. Reproduction from man + +%% +%% I - Documentation +%% + +%% I.1 - Incompatibilities + +% Package ulem: +% The package ulem has a lot of oddities. Using it is not always a +% good idea. If you really want to do so, you should import it with +% the [normalem] option, as such : +% \usepackage[normalem]{ulem} +% Otherwise, it overrides \emph to underline the emphasized text. So +% far so good, but underlined text is typesetted in a box, which means +% that linebreaks don't happen automatically. Since \abstract (among +% others) uses \emph, the abstract is unreadable by default. +% Please read thoroughly ulem's doc before using it. +% See also: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=underline + +%% +%% II - General LaTeX boilerplate +%% + +%% II.1 - Definition + +\NeedsTeXFormat{LaTeX2e}[1995/12/01] +\ProvidesClass{42-en}[2014/08/22 v2.1 + LaTeX class for 42-themed documents] + +%% II.2 - Class options and parent class + +\newcommand{\summarytitle}{Sommario}% + +\DeclareOption*{% + \PassOptionsToClass{\CurrentOption}{report} +} + +\ProcessOptions\relax +\LoadClass[a4paper,12pt,onecolumn]{report} + +%% II.3 - Imports + +\usepackage[top=1in,bottom=1in,left=1in,right=1in]{geometry} +\usepackage[pdftex]{graphicx} +\usepackage{url} +\usepackage{fancyhdr} +\usepackage{array} +\usepackage[table]{xcolor} +\usepackage[utf8]{inputenc} +\usepackage[T1]{fontenc} +\usepackage{lmodern} +\usepackage{listings} +\usepackage{tabularx} +\usepackage{textcomp} +\usepackage{color} +\usepackage[pdftex]{hyperref} +\usepackage{fancybox} +\usepackage{float} +\usepackage{atbeginend} % provided locally : atbeginend.sty +\usepackage{tocloft} % provided locally : tocloft.sty +\usepackage{multirow} % provided locally : multirow.sty +\usepackage[italian]{babel} +\usepackage{minted} % provided locally : minted.sty +% Minted requires the Python "Pygments" librairy (http://pygments.org/). +% Pygments can be easily installed with the "easy_install" paquet manager +% from the "python-setuptools" paquet (sudo easy_install Pygments). +\usepackage{pifont,mdframed} +\usepackage{wallpaper} + +%% III - Lengths and color redefinitions + +%% III.1 - Lengths + +\AfterBegin{enumerate}{ + \itemsep10pt% +} +\AfterBegin{itemize}{ + \itemsep5pt% + \renewcommand{\labelitemi}{$\bullet$}% + \renewcommand{\labelitemii}{$\circ$}% +} + +\BeforeBegin{enumerate}{\vspace{15pt}} +\AfterEnd{enumerate}{\vspace{15pt}} + +\BeforeBegin{itemize}{\vspace{15pt}} +\AfterEnd{itemize}{\vspace{15pt}} + +\BeforeBegin{lstlisting}{\vspace{15pt}} +\AfterEnd{lstlisting}{\vspace{15pt}} + +\BeforeBegin{tabularx}{\vspace{15pt}} +\AfterEnd{tabularx}{\vspace{15pt}} + +%% III.2 - Colors + +\definecolor{nicergreen}{rgb}{0,0.502,0} +\definecolor{nicerblue}{rgb}{0,0.302,1} +\definecolor{nicerorange}{rgb}{1,0.502,0} +\definecolor{nicergrey}{rgb}{0.502,0.502,0.502} +\definecolor{nicerred}{rgb}{0.626,0,0} +\definecolor{hintbg}{rgb}{1.0,1.0,0.75} +\definecolor{warnbg}{rgb}{1.0,0.75,0.75} +\definecolor{infobg}{rgb}{0.75,0.75,1.0} +\definecolor{bibliotechbg}{RGB}{239,253,255} +\definecolor{lightgrey}{rgb}{0.95,0.95,0.95} +\definecolor{darkgrey}{rgb}{0.1,0.1,0.1} +\definecolor{assholeblack}{rgb}{0,0,0} + +%% III.3 - Hyperlinks + +\hypersetup +{ + colorlinks, +% citecolor=black, % +% filecolor=black, % + linkcolor=black, % black links + urlcolor=blue % blue URLs +} + +%% III.4 - Listings + +\lstset +{ + backgroundcolor=\color{gray!15}, + basicstyle=\small\ttfamily, + breaklines=true, + columns=fullflexible, + frame=lines, + tabsize=4, + numbers=none, %numbers=left, + numberstyle=\scriptsize\ttfamily, + numbersep=5pt, + showspaces=false, + showstringspaces=false, + showtabs=false, + breaklines=true, + upquote=true, + float +} + +%% III.5 - Page layout + +\makeatletter +\pagestyle{fancy} +\lhead{\@title} +\rhead{\@subtitle} +\cfoot{\thepage} +\makeatother + +%% III.6 - Roman chapter style + +% custom sections style + +\renewcommand{\thechapter}{\Roman{chapter}} + +% Using roman numerals makes the TOC section/subsection numbers +% overflow on the right. This adds some margin to avoid that kind of +% problems. (requires \usepackage{tocloft}) +\setlength{\cftchapnumwidth}{1.5cm} +\setlength{\cftsecnumwidth}{1.5cm} +\setlength{\cftsubsecnumwidth}{1.3cm} +\setlength{\cftsubsubsecnumwidth}{1.6cm} +\setlength{\cftaftertoctitleskip}{0.5cm} + +%% IV - Frontpage customization + +%% IV.1 - Custom fields +\makeatletter +\newcommand{\website}[1]{\def \@website {#1}} +\website{} + +\newcommand{\subtitle}[1]{\def \@subtitle {#1}} +\subtitle{} + +\newcommand{\schoollogo}[1]{\def \@schoollogo {#1}} +\schoollogo{42_logo.pdf} + +\newcommand{\summary}[1]{\def \@summary {#1}} +\summary{} + +\edef\@authors{} +\newcommand{\member}[2]{% + \protected@edef\@authors{\@authors #1 \protect\url{#2}\\} + \author{\@authors} +} +\author{} + +%% IV.2 - Redefine \maketitle + +\makeatletter +\def \maketitle { + \begin{titlepage} + \begin{center} + %\begin{figure}[t] + \includegraphics[height=8cm]{\@schoollogo} + %\end{figure} + \vskip 5em + {\huge \@title} + \vskip 2em + {\LARGE \@subtitle} + \vskip 4em + \end{center} + \begin{center} + \@author + \end{center} + \vskip 5em + \begin{center} + \emph{\summarytitle : \@summary} + \end{center} + \end{titlepage} +} +\makeatother + +\TileWallPaper{\paperwidth}{\paperheight}{back} +%% IV.3 - Exercice number + +\newcounter{exerciceCounter} +\newcommand*{\exercicenumber}{ + \ifnum\value{exerciceCounter}<10 0\fi + \arabic{exerciceCounter} +} + +\newcommand*{\startexercices}{ + \setcounter{exerciceCounter}{0} +} + +\newcommand*{\nextexercice}{ + \stepcounter{exerciceCounter} +} + +\newcounter{itemizeCounter} +\setcounter{itemizeCounter}{0} +\BeforeBegin{itemize}{ + \addtocounter{itemizeCounter}{1} +} + +\AfterEnd{itemize}{ + \addtocounter{itemizeCounter}{-1} + \ifnum\value{itemizeCounter} = 0 + \stepcounter{exerciceCounter} + \fi +} + +%% V - Custom helper commands + +%% V.1 - Hint/Warn + +% hint command + +\newcommand{\kbox}[3] +{ + \vskip 15pt + \noindent + \colorbox{#1} + { + \begin{tabular*}{0.97\textwidth}{m{4em}m{0.8\textwidth}} + \includegraphics[width=4em]{#2} + & {\ttfamily\footnotesize #3}\\ + \end{tabular*} + } + \vskip 15pt +} + +\newcommand{\hint}[1]{\kbox{hintbg}{helphint.pdf}{#1}} +\newcommand{\warn}[1]{\kbox{warnbg}{warn.pdf}{#1}} +\newcommand{\info}[1]{\kbox{infobg}{info.pdf}{#1}} + +%% V.2 Lisibility helper + +\makeatletter +\newcommand{\mso}[1]{ + \ttfamily #1 \normalfont +} + +%% V.3 Exercise headers + +\makeatletter +\newcommand{\turnindir}[1]{\def \@turnindir {#1}} +\newcommand{\daypiscine}[1]{\def \@daypiscine {#1}} +\newcommand{\extitle}[1]{\def \@extitle {#1}} +\newcommand{\exnumber}[1]{\def \@exnumber {#1}} +\newcommand{\exscore}[1]{\def \@exscore {#1}} +\newcommand{\exflags}[1][-W -Wall -Werror]{\def \@exflags {#1}} +\newcommand{\excompil}[1][gcc]{\def \@excompil {#1}} +\newcommand{\exrules}[1][n/a]{\def \@exrules {#1}} +\newcommand{\exfiles}[1]{\def \@exfiles {#1}} +\newcommand{\exnotes}[1][n/a]{\def \@exnotes {#1}} +\newcommand{\exauthorize}[1]{\def \@exauthorize {#1}} +\newcommand{\exforbidden}[1]{\def \@exforbidden {#1}} +\newcommand{\exmake}[1][No]{\def \@exmake {#1}} + +% Default values +\turnindir{} +\daypiscine{} +\extitle{} +\exnumber{} +\exscore{} +\exflags{} +\excompil{} +\exrules{} +\exfiles{} +\exnotes{} +\exauthorize{Nessuna} +\exforbidden{Nessuna} +\exmake{} + +%Header pour exercices sans rien a "rendre" +\newcommand{\makeheaderbasic} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Esercizio : \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + +%% \multicolumn{4}{|>{\raggedright}m{15cm}|} +%% {\small Notes : \ttfamily \@exnotes } +%% \\ \hline +\end{tabularx} +%% \exnotes +\exrules +\exmake +%\exauthorize +\exforbidden{Nessuna} +\extitle{} +\exnumber{} +} + +%Header pour exercices sans code mais fichiers a rendre +\newcommand{\makeheaderfiles} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Esercizio \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Cartella per la consegna : \ttfamily + $ex\@exnumber/$ } + \\ \hline + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small File da consegnare : \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Funzioni permesse : \ttfamily \@exauthorize } + \\ \hline + +%% \multicolumn{4}{|>{\raggedright}m{15cm}|} +%% {\small Notes : \ttfamily \@exnotes } +%% \\ \hline +\end{tabularx} +%% \exnotes +\exrules +\exmake +\exauthorize{Nessuna} +\exforbidden{Nessuna} +\extitle{} +\exnumber{} +} + +%Header for exercices without turn in repository +\newcommand{\makeheaderfilesnodirectory} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercice : \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small File da consegnare : \ttfamily \@exauthorize } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Funzioni permesse : \ttfamily \@exnotes } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Notes : \ttfamily \@exnotes } + \\ \hline +\end{tabularx} +\exnotes +\exrules +\exmake +\exauthorize{Nessuna} +\exforbidden{Nessuna} +\extitle{} +\exnumber{} +} + +%Header pour exercices sans code mais fichiers a rendre +\newcommand{\makeheaderfilesforbidden} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercise : \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Cartella per la consegna : \ttfamily + $ex\@exnumber/$ } + \\ \hline + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small File da consegnare : \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Funzioni vietate : \ttfamily \@exforbidden } + \\ \hline + +%% \multicolumn{4}{|>{\raggedright}m{15cm}|} +%% {\small Remarks : \ttfamily \@exnotes } +%% \\ \hline +\end{tabularx} +%% \exnotes +\exrules +\exmake +\exauthorize{Nessuna} +\exforbidden{Nessuna} +\extitle{} +\exnumber{} +} + +%Header pour exercices de code +\newcommand{\makeheadercode} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercise \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} + %% {\scriptsize Score : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Cartella per la consegna: \ttfamily + $ex\@exnumber/$ } + \\ \hline + + \multicolumn{2}{|>{\raggedright}m{7.5cm}} + {\small Compilatore: \ttfamily \@excompil } & + \multicolumn{2}{|>{\raggedright}m{7.5cm}|} + {\small Flag di compilazione: + \ttfamily \@exflags } + \\ \hline + + \multicolumn{2}{|>{\raggedright}m{7.52cm}} + {\small Makefile: \ttfamily{\@exmake}} & + \multicolumn{2}{|>{\raggedright}m{7.5cm}|} + {Regole del Makefile: \ttfamily \@exrules } \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small File da consegnare: \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Notes : \ttfamily \@exnotes } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Funzioni vietate: \ttfamily \@exforbidden } + \\ \hline +\end{tabularx} +\exnotes +\exrules +\exmake +\exforbidden{Nessuna} +\extitle{} +\exnumber{} +} + + +\newcommand{\ftname}[1]{\def \@ftname {#1}} +\newcommand{\ftprototype}[1]{\def \@ftprototype {#1}} +\newcommand{\ftdesc}[1]{\def \@ftdesc {#1}} +\newcommand{\ftparams}[1]{\def \@ftparams {#1}} +\newcommand{\ftret}[1]{\def \@ftret {#1}} +\newcommand{\ftfuncts}[1]{\def \@ftfuncts {#1}} +\newcommand{\ftturnin}[1]{\def \@ftturnin {#1}} +\newcommand{\ftmakefile}[1]{\def \@ftmakefile {#1}} +\newcommand{\ftlibft}[1]{\def \@ftlibft {#1}} +\newcommand{\ftcompil}[1]{\def \@ftcompil {#1}} + +\ftname{} +\ftprototype{} +\ftdesc{} +\ftparams{} +\ftret{} +\ftfuncts{} +\ftturnin{} +\ftmakefile{} +\ftlibft{} +\ftcompil{} + + +\newcolumntype{s}{>{\hsize=.5\hsize}X} +\newcolumntype{b}{>{\hsize=1.5\hsize}X} +\newcommand{\makeheaderfct} +{ + \noindent + + \begin{tabularx}{\textwidth}{| s | b |} \hline + + \textbf{Nome della funzione} & \texttt{\@ftname} \\ \hline + \textbf{Prototipo} & \texttt{\@ftprototype} \\ \hline + \textbf{File da consegnare} & \texttt{\@ftturnin} \\ \hline + \textbf{Parametri} & \texttt{\@ftparams} \\ \hline + \textbf{Valore di ritorno} & \texttt{\@ftret} \\ \hline + \textbf{Funzioni esterne permesse} & \texttt{\@ftfuncts} \\ \hline + \textbf{Descrizione} & \texttt{\@ftdesc} \\ \hline + +\end{tabularx} +} + +\newcommand{\makeheaderlib} +{ + \noindent + + \begin{tabularx}{\textwidth}{| s | b |} \hline + + \textbf{Nome del programma} & \texttt{\@ftname} \\ \hline + \textbf{File da consegnare} & \texttt{\@ftturnin} \\ \hline + \textbf{Makefile} & \texttt{\@ftmakefile} \\ \hline + \textbf{Funzioni esterne permesse} & \texttt{\@ftfuncts} \\ \hline + \textbf{Libft permessa} & \texttt{\@ftlibft} \\ \hline + \textbf{Descrizione} & \texttt{\@ftdesc} \\ \hline + +\end{tabularx} +} + +\newcommand{\makeheaderprg} +{ + \noindent + + \begin{tabularx}{\textwidth}{| s | b |} \hline + + \textbf{Nome del programma} & \texttt{\@ftname} \\ \hline + \textbf{File da consegnare} & \texttt{\@ftturnin} \\ \hline + \textbf{Makefile} & \texttt{\@ftmakefile} \\ \hline + \textbf{Argomenti} & \texttt{\@ftparams} \\ \hline + \textbf{Funzioni esterne permesse} & \texttt{\@ftfuncts} \\ \hline + \textbf{Libft permessa} & \texttt{\@ftlibft} \\ \hline + \textbf{Descrizione} & \texttt{\@ftdesc} \\ \hline + +\end{tabularx} +} + + +\newcommand{\exmandatory}{Esercizio obbligatorio} +\newcommand{\exretrovalid}{Esercizio retro convalidato} +\newcommand{\exoptional}{Esercizio facoltativo} + +\newcommand{\exercice}{Esercizio} + +%% V.4 Reproduction from man +\newcommand{\reproductionfromman}[1]{Riproduci il comportamento della funzione \texttt{#1} (man #1).} + +%% VI - Syntactic highlights + + +%% Styles: +%% ~~~~~~~ +%% * monokai: +%% This style mimics the Monokai color scheme. +%% * manni: +%% A colorful style, inspired by the terminal highlighting style. +%% * rrt: +%% Minimalistic ``rrt'' theme, based on Zap and Emacs defaults. +%% * perldoc: +%% Style similar to the style used in the perldoc code blocks. +%% * borland: +%% Style similar to the style used in the borland IDEs. +%% * colorful: +%% A colorful style, inspired by CodeRay. +%% * default: +%% The default style (inspired by Emacs 22). +%% * murphy: +%% Murphy's style from CodeRay. +%% * vs: +%% +%% * trac: +%% Port of the default trac highlighter design. +%% * tango: +%% The Crunchy default Style inspired from the color palette from the Tango Icon Theme Guidelines. +%% * fruity: +%% Pygments version of the ``native'' vim theme. +%% * autumn: +%% A colorful style, inspired by the terminal highlighting style. +%% * bw: +%% +%% * emacs: +%% The default style (inspired by Emacs 22). +%% * vim: +%% Styles somewhat like vim 7.0 +%% * pastie: +%% Style similar to the pastie default style. +%% * friendly: +%% A modern style based on the VIM pyte theme. +%% * native: +%% Pygments version of the ``native'' vim theme. + + + +%\usemintedstyle{monokai} +%\usemintedstyle{manni} +%\usemintedstyle{rrt} +%\usemintedstyle{perldoc} +%\usemintedstyle{borland} +%\usemintedstyle{colorful} +%\usemintedstyle{default} +%\usemintedstyle{murphy} +%\usemintedstyle{vs} +%\usemintedstyle{trac} +%\usemintedstyle{tango} +%\usemintedstyle{fruity} +%\usemintedstyle{autumn} +%\usemintedstyle{bw} +%\usemintedstyle{emacs} +%\usemintedstyle{vim} +%\usemintedstyle{pastie} +%\usemintedstyle{friendly} +%\usemintedstyle{native} + +\makeatletter +\newenvironment{42ccode}{% + \VerbatimEnvironment + \usemintedstyle{emacs} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{c} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42phpcode}{% + \VerbatimEnvironment + \usemintedstyle{emacs} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{html+php} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42jscode}{% + \VerbatimEnvironment + \usemintedstyle{emacs} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{js} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\definecolor{darcula-back}{RGB}{35, 37, 37} + +\makeatletter +\newenvironment{42javacode}{% + \VerbatimEnvironment + \usemintedstyle{monokai} + \minted@resetoptions + \definecolor{dark}{RGB}{35, 37, 37} + \setkeys{minted@opt}{bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{java} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42xmlcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{xml} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42yamlcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{yaml} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42cppcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{c++} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + + +\makeatletter +\newenvironment{42ocamlcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{ocaml} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + + +\makeatletter +\newenvironment{42asmcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{nasm} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\lstnewenvironment{42console} { + \lstset { + extendedchars=true, + literate={✓}{{\checkmark}}1, + basicstyle=\color{lightgrey}\scriptsize\ttfamily, + backgroundcolor=\color{assholeblack}, + breaklines=true, + numberstyle=\scriptsize, + columns=flexible, + keepspaces=false, + } +}{} + +\newenvironment{42warning} + {\vspace*{1\baselineskip} + \par\begin{mdframed}[linewidth=2pt,linecolor=red]% + \begin{list}{}{\leftmargin=1cm + \labelwidth=\leftmargin}\item[\Large\ding{43}]} + {\end{list}\end{mdframed}\par \vspace*{1\baselineskip}} \ No newline at end of file diff --git a/resources/latex/42-ja.cls b/resources/latex/42-ja.cls new file mode 100644 index 00000000..9c91472a --- /dev/null +++ b/resources/latex/42-ja.cls @@ -0,0 +1,889 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% 42-ja.cls +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% Authors: +% - Maxime "zaz" Montinet +% - David "Thor" Giron +% +% Contributors: +% - Mathieu Mahé +% - Gaëtan JUVIN +% - Unknown for now +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +% This class provides a layout for teaching material at 42. +% +% This class is organized this way : +% +% I - Documentation +% 1. Incompatibilites +% II - General LaTeX boilerplate +% 1. Definition +% 2. Class options and parent class +% 3. Imports +% III - Lengths and color redefinitions +% 1. Lenghts +% 2. Colors +% 3. Hyperlinks +% 4. Listings +% 5. Page layout +% 6. Roman numerals for chapters +% IV - Frontpage customization +% 1. Custom fields +% 2. Redefinition of \maketitle +% 3. Exercice number +% V - Custom helper commands +% 1. Hint/warn +% 2. Lisibility helper +% 3. Exercise headers +% 4. Reproduction from man + +%% +%% I - Documentation +%% + +%% I.1 - Incompatibilities + +% Package ulem: +% The package ulem has a lot of oddities. Using it is not always a +% good idea. If you really want to do so, you should import it with +% the [normalem] option, as such : +% \usepackage[normalem]{ulem} +% Otherwise, it overrides \emph to underline the emphasized text. So +% far so good, but underlined text is typesetted in a box, which means +% that linebreaks don't happen automatically. Since \abstract (among +% others) uses \emph, the abstract is unreadable by default. +% Please read thoroughly ulem's doc before using it. +% See also: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=underline + +%% +%% II - General LaTeX boilerplate +%% + +%% II.1 - Definition + +\NeedsTeXFormat{LaTeX2e}[1995/12/01] +\ProvidesClass{42-ja}[2019/07/08 v1.0 + LaTeX class for 42-themed documents] + +%% II.2 - Class options and parent class + +\newcommand{\summarytitle}{Summary}% + +\DeclareOption*{% + \PassOptionsToClass{\CurrentOption}{report} +} + +\ProcessOptions\relax +\LoadClass[a4paper,12pt,onecolumn]{report} + +%% II.3 - Imports + +% \usepackage{CJKutf8} +\usepackage[whole]{bxcjkjatype} +\usepackage[top=1in,bottom=1in,left=1in,right=1in]{geometry} +\usepackage[pdftex]{graphicx} +\usepackage{url} +\usepackage{fancyhdr} +\usepackage{array} +\usepackage[table]{xcolor} +\usepackage[utf8]{inputenc} +\usepackage[T1]{fontenc} +\usepackage{lmodern} +\usepackage{listings} +\usepackage{tabularx} +\usepackage{textcomp} +\usepackage{color} +\usepackage[pdftex]{hyperref} +\usepackage{fancybox} +\usepackage{float} +\usepackage{atbeginend} % provided locally : atbeginend.sty +\usepackage{tocloft} % provided locally : tocloft.sty +\usepackage{multirow} % provided locally : multirow.sty +\usepackage[english]{babel} +\usepackage{minted} % provided locally : minted.sty +% Minted requires the Python "Pygments" librairy (http://pygments.org/). +% Pygments can be easily installed with the "easy_install" paquet manager +% from the "python-setuptools" paquet (sudo easy_install Pygments). +\usepackage{pifont,mdframed} +\usepackage{wallpaper} + +%% III - Lengths and color redefinitions + +%% III.1 - Lengths + +\AfterBegin{enumerate}{ + \itemsep10pt% +} +\AfterBegin{itemize}{ + \itemsep5pt% + \renewcommand{\labelitemi}{$\bullet$}% + \renewcommand{\labelitemii}{$\circ$}% +} + +\BeforeBegin{enumerate}{\vspace{15pt}} +\AfterEnd{enumerate}{\vspace{15pt}} + +\BeforeBegin{itemize}{\vspace{15pt}} +\AfterEnd{itemize}{\vspace{15pt}} + +\BeforeBegin{lstlisting}{\vspace{15pt}} +\AfterEnd{lstlisting}{\vspace{15pt}} + +\BeforeBegin{tabularx}{\vspace{15pt}} +\AfterEnd{tabularx}{\vspace{15pt}} + +%% III.2 - Colors + +\definecolor{nicergreen}{rgb}{0,0.502,0} +\definecolor{nicerblue}{rgb}{0,0.302,1} +\definecolor{nicerorange}{rgb}{1,0.502,0} +\definecolor{nicergrey}{rgb}{0.502,0.502,0.502} +\definecolor{nicerred}{rgb}{0.626,0,0} +\definecolor{hintbg}{rgb}{1.0,1.0,0.75} +\definecolor{warnbg}{rgb}{1.0,0.75,0.75} +\definecolor{infobg}{rgb}{0.75,0.75,1.0} +\definecolor{bibliotechbg}{RGB}{239,253,255} +\definecolor{lightgrey}{rgb}{0.95,0.95,0.95} +\definecolor{darkgrey}{rgb}{0.1,0.1,0.1} +\definecolor{assholeblack}{rgb}{0,0,0} + +%% III.3 - Hyperlinks + +\hypersetup +{ + colorlinks, +% citecolor=black, % +% filecolor=black, % + linkcolor=black, % black links + urlcolor=blue % blue URLs +} + +%% III.4 - Listings + +\lstset +{ + backgroundcolor=\color{gray!15}, + basicstyle=\small\ttfamily, + breaklines=true, + columns=fullflexible, + frame=lines, + tabsize=4, + numbers=none, %numbers=left, + numberstyle=\scriptsize\ttfamily, + numbersep=5pt, + showspaces=false, + showstringspaces=false, + showtabs=false, + breaklines=true, + upquote=true, + float +} + +%% III.5 - Page layout + +\makeatletter +\pagestyle{fancy} +\lhead{\@title} +\rhead{\@subtitle} +\cfoot{\thepage} +\makeatother + +%% III.6 - Roman chapter style + +% custom sections style + +\renewcommand{\thechapter}{\Roman{chapter}} + +% Using roman numerals makes the TOC section/subsection numbers +% overflow on the right. This adds some margin to avoid that kind of +% problems. (requires \usepackage{tocloft}) +\setlength{\cftchapnumwidth}{1.5cm} +\setlength{\cftsecnumwidth}{1.5cm} +\setlength{\cftsubsecnumwidth}{1.3cm} +\setlength{\cftsubsubsecnumwidth}{1.6cm} +\setlength{\cftaftertoctitleskip}{0.5cm} + +%% IV - Frontpage customization + +%% IV.1 - Custom fields +\makeatletter +\newcommand{\website}[1]{\def \@website {#1}} +\website{} + +\newcommand{\subtitle}[1]{\def \@subtitle {#1}} +\subtitle{} + +\newcommand{\schoollogo}[1]{\def \@schoollogo {#1}} +\schoollogo{42_logo.pdf} + +\newcommand{\summary}[1]{\def \@summary {#1}} +\summary{} + +\edef\@authors{} +\newcommand{\member}[2]{% + \protected@edef\@authors{\@authors #1 \protect\url{#2}\\} + \author{\@authors} +} +\author{} + +%% IV.2 - Redefine \maketitle + +\makeatletter +\def \maketitle { + \begin{titlepage} + \begin{center} + %\begin{figure}[t] + \includegraphics[height=8cm]{\@schoollogo} + %\end{figure} + \vskip 5em + {\huge \@title} + \vskip 2em + {\LARGE \@subtitle} + \vskip 4em + \end{center} + \begin{center} + \@author + \end{center} + \vskip 5em + \begin{center} + \emph{\summarytitle : \@summary} + \end{center} + \end{titlepage} +} +\makeatother + +\TileWallPaper{\paperwidth}{\paperheight}{back} +%% IV.3 - Exercice number + +\newcounter{exerciceCounter} +\newcommand*{\exercicenumber}{ + \ifnum\value{exerciceCounter}<10 0\fi + \arabic{exerciceCounter} +} + +\newcommand*{\startexercices}{ + \setcounter{exerciceCounter}{0} +} + +\newcommand*{\nextexercice}{ + \stepcounter{exerciceCounter} +} + +\newcounter{itemizeCounter} +\setcounter{itemizeCounter}{0} +\BeforeBegin{itemize}{ + \addtocounter{itemizeCounter}{1} +} + +\AfterEnd{itemize}{ + \addtocounter{itemizeCounter}{-1} + \ifnum\value{itemizeCounter} = 0 + \stepcounter{exerciceCounter} + \fi +} + +%% V - Custom helper commands + +%% V.1 - Hint/Warn + +% hint command + +\newcommand{\kbox}[3] +{ + \vskip 15pt + \noindent + \colorbox{#1} + { + \begin{tabular*}{0.97\textwidth}{m{4em}m{0.8\textwidth}} + \includegraphics[width=4em]{#2} + & {\ttfamily\footnotesize #3}\\ + \end{tabular*} + } + \vskip 15pt +} + +\newcommand{\hint}[1]{\kbox{hintbg}{helphint.pdf}{#1}} +\newcommand{\warn}[1]{\kbox{warnbg}{warn.pdf}{#1}} +\newcommand{\info}[1]{\kbox{infobg}{info.pdf}{#1}} + +%% V.2 Lisibility helper + +\makeatletter +\newcommand{\mso}[1]{ + \ttfamily #1 \normalfont +} + +%% V.3 Exercise headers + +\makeatletter +\newcommand{\turnindir}[1]{\def \@turnindir {#1}} +\newcommand{\daypiscine}[1]{\def \@daypiscine {#1}} +\newcommand{\extitle}[1]{\def \@extitle {#1}} +\newcommand{\exnumber}[1]{\def \@exnumber {#1}} +\newcommand{\exscore}[1]{\def \@exscore {#1}} +\newcommand{\exflags}[1][-W -Wall -Werror]{\def \@exflags {#1}} +\newcommand{\excompil}[1][gcc]{\def \@excompil {#1}} +\newcommand{\exrules}[1][n/a]{\def \@exrules {#1}} +\newcommand{\exfiles}[1]{\def \@exfiles {#1}} +\newcommand{\exnotes}[1][n/a]{\def \@exnotes {#1}} +\newcommand{\exauthorize}[1]{\def \@exauthorize {#1}} +\newcommand{\exforbidden}[1]{\def \@exforbidden {#1}} +\newcommand{\exmake}[1][No]{\def \@exmake {#1}} + +% Default values +\turnindir{} +\daypiscine{} +\extitle{} +\exnumber{} +\exscore{} +\exflags{} +\excompil{} +\exrules{} +\exfiles{} +\exnotes{} +\exauthorize{None} +\exforbidden{None} +\exmake{} + +%Header pour exercices sans rien a "rendre" +\newcommand{\makeheaderbasic} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercise : \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + +%% \multicolumn{4}{|>{\raggedright}m{15cm}|} +%% {\small Notes : \ttfamily \@exnotes } +%% \\ \hline +\end{tabularx} +%% \exnotes +\exrules +\exmake +%\exauthorize +\exforbidden{None} +\extitle{} +\exnumber{} +} + +%Header pour exercices sans code mais fichiers a rendre +\newcommand{\makeheaderfiles} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercise \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small 提出するディレクトリ : \ttfamily + $ex\@exnumber/$ } + \\ \hline + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small 提出するファイル : \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small 使用可能な関数 : \ttfamily \@exauthorize } + \\ \hline + +%% \multicolumn{4}{|>{\raggedright}m{15cm}|} +%% {\small Notes : \ttfamily \@exnotes } +%% \\ \hline +\end{tabularx} +%% \exnotes +\exrules +\exmake +\exauthorize{None} +\exforbidden{None} +\extitle{} +\exnumber{} +} + +%Header for exercices without turn in repository +\newcommand{\makeheaderfilesnodirectory} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercice : \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small 提出するファイル : \ttfamily \@exauthorize } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small 使用可能な関数 : \ttfamily \@exnotes } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small メモ : \ttfamily \@exnotes } + \\ \hline +\end{tabularx} +\exnotes +\exrules +\exmake +\exauthorize{None} +\exforbidden{None} +\extitle{} +\exnumber{} +} + +%Header pour exercices sans code mais fichiers a rendre +\newcommand{\makeheaderfilesforbidden} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercise : \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small 提出するディレクトリ : \ttfamily + $ex\@exnumber/$ } + \\ \hline + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small 提出するファイル : \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small 使用禁止な関数 : \ttfamily \@exforbidden } + \\ \hline + +%% \multicolumn{4}{|>{\raggedright}m{15cm}|} +%% {\small Remarks : \ttfamily \@exnotes } +%% \\ \hline +\end{tabularx} +%% \exnotes +\exrules +\exmake +\exauthorize{None} +\exforbidden{None} +\extitle{} +\exnumber{} +} + +%Header pour exercices de code +\newcommand{\makeheadercode} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercise \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} + %% {\scriptsize Score : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small 提出するディレクトリ: \ttfamily + $ex\@exnumber/$ } + \\ \hline + + \multicolumn{2}{|>{\raggedright}m{7.5cm}} + {\small コンパイラ: \ttfamily \@excompil } & + \multicolumn{2}{|>{\raggedright}m{7.5cm}|} + {\small コンパイル時のフラグ: + \ttfamily \@exflags } + \\ \hline + + \multicolumn{2}{|>{\raggedright}m{7.52cm}} + {\small Makefile: \ttfamily{\@exmake}} & + \multicolumn{2}{|>{\raggedright}m{7.5cm}|} + {Makefileのルール: \ttfamily \@exrules } \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small 提出するファイル: \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small メモ: \ttfamily \@exnotes } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small 使用禁止な関数: \ttfamily \@exforbidden } + \\ \hline +\end{tabularx} +\exnotes +\exrules +\exmake +\exforbidden{None} +\extitle{} +\exnumber{} +} + + +\newcommand{\ftname}[1]{\def \@ftname {#1}} +\newcommand{\ftprototype}[1]{\def \@ftprototype {#1}} +\newcommand{\ftdesc}[1]{\def \@ftdesc {#1}} +\newcommand{\ftparams}[1]{\def \@ftparams {#1}} +\newcommand{\ftret}[1]{\def \@ftret {#1}} +\newcommand{\ftfuncts}[1]{\def \@ftfuncts {#1}} +\newcommand{\ftturnin}[1]{\def \@ftturnin {#1}} +\newcommand{\ftmakefile}[1]{\def \@ftmakefile {#1}} +\newcommand{\ftlibft}[1]{\def \@ftlibft {#1}} +\newcommand{\ftcompil}[1]{\def \@ftcompil {#1}} + +\ftname{} +\ftprototype{} +\ftdesc{} +\ftparams{} +\ftret{} +\ftfuncts{} +\ftturnin{} +\ftmakefile{} +\ftlibft{} +\ftcompil{} + + +\newcolumntype{s}{>{\hsize=.5\hsize}X} +\newcolumntype{b}{>{\hsize=1.5\hsize}X} +\newcommand{\makeheaderfct} +{ + \noindent + + \begin{tabularx}{\textwidth}{| s | b |} \hline + + \textbf{Function name} & \texttt{\@ftname} \\ \hline + \textbf{Prototype} & \texttt{\@ftprototype} \\ \hline + \textbf{Turn in files} & \texttt{\@ftturnin} \\ \hline + \textbf{Parameters} & \texttt{\@ftparams} \\ \hline + \textbf{Return value} & \texttt{\@ftret} \\ \hline + \textbf{External functs.} & \texttt{\@ftfuncts} \\ \hline + \textbf{Description} & \texttt{\@ftdesc} \\ \hline + +\end{tabularx} +} + +\newcommand{\makeheaderlib} +{ + \noindent + + \begin{tabularx}{\textwidth}{| s | b |} \hline + + \textbf{Program name} & \texttt{\@ftname} \\ \hline + \textbf{Turn in files} & \texttt{\@ftturnin} \\ \hline + \textbf{Makefile} & \texttt{\@ftmakefile} \\ \hline + \textbf{External functs.} & \texttt{\@ftfuncts} \\ \hline + \textbf{Libft authorized} & \texttt{\@ftlibft} \\ \hline + \textbf{Description} & \texttt{\@ftdesc} \\ \hline + +\end{tabularx} +} + +\newcommand{\makeheaderprg} +{ + \noindent + + \begin{tabularx}{\textwidth}{| s | b |} \hline + + \textbf{Program name} & \texttt{\@ftname} \\ \hline + \textbf{Turn in files} & \texttt{\@ftturnin} \\ \hline + \textbf{Makefile} & \texttt{\@ftmakefile} \\ \hline + \textbf{Arguments} & \texttt{\@ftparams} \\ \hline + \textbf{External functs.} & \texttt{\@ftfuncts} \\ \hline + \textbf{Libft authorized} & \texttt{\@ftlibft} \\ \hline + \textbf{Description} & \texttt{\@ftdesc} \\ \hline + +\end{tabularx} +} + + +\newcommand{\exmandatory}{Mandatory exercise} +\newcommand{\exretrovalid}{Retrovalidated exercise} +\newcommand{\exoptional}{Optional exercise} + +\newcommand{\exercice}{Exercise} + +%% V.4 Reproduction from man +\newcommand{\reproductionfromman}[1]{\texttt{#1}関数の動作を再現しなさい。(man #1)} + +%% VI - Syntactic highlights + + +%% Styles: +%% ~~~~~~~ +%% * monokai: +%% This style mimics the Monokai color scheme. +%% * manni: +%% A colorful style, inspired by the terminal highlighting style. +%% * rrt: +%% Minimalistic ``rrt'' theme, based on Zap and Emacs defaults. +%% * perldoc: +%% Style similar to the style used in the perldoc code blocks. +%% * borland: +%% Style similar to the style used in the borland IDEs. +%% * colorful: +%% A colorful style, inspired by CodeRay. +%% * default: +%% The default style (inspired by Emacs 22). +%% * murphy: +%% Murphy's style from CodeRay. +%% * vs: +%% +%% * trac: +%% Port of the default trac highlighter design. +%% * tango: +%% The Crunchy default Style inspired from the color palette from the Tango Icon Theme Guidelines. +%% * fruity: +%% Pygments version of the ``native'' vim theme. +%% * autumn: +%% A colorful style, inspired by the terminal highlighting style. +%% * bw: +%% +%% * emacs: +%% The default style (inspired by Emacs 22). +%% * vim: +%% Styles somewhat like vim 7.0 +%% * pastie: +%% Style similar to the pastie default style. +%% * friendly: +%% A modern style based on the VIM pyte theme. +%% * native: +%% Pygments version of the ``native'' vim theme. + + + +%\usemintedstyle{monokai} +%\usemintedstyle{manni} +%\usemintedstyle{rrt} +%\usemintedstyle{perldoc} +%\usemintedstyle{borland} +%\usemintedstyle{colorful} +%\usemintedstyle{default} +%\usemintedstyle{murphy} +%\usemintedstyle{vs} +%\usemintedstyle{trac} +%\usemintedstyle{tango} +%\usemintedstyle{fruity} +%\usemintedstyle{autumn} +%\usemintedstyle{bw} +%\usemintedstyle{emacs} +%\usemintedstyle{vim} +%\usemintedstyle{pastie} +%\usemintedstyle{friendly} +%\usemintedstyle{native} + +\makeatletter +\newenvironment{42ccode}{% + \VerbatimEnvironment + \usemintedstyle{emacs} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{c} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42phpcode}{% + \VerbatimEnvironment + \usemintedstyle{emacs} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{html+php} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42jscode}{% + \VerbatimEnvironment + \usemintedstyle{emacs} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{js} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\definecolor{darcula-back}{RGB}{35, 37, 37} + +\makeatletter +\newenvironment{42javacode}{% + \VerbatimEnvironment + \usemintedstyle{monokai} + \minted@resetoptions + \definecolor{dark}{RGB}{35, 37, 37} + \setkeys{minted@opt}{bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{java} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42xmlcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{xml} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42yamlcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{yaml} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42cppcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{c++} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + + +\makeatletter +\newenvironment{42ocamlcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{ocaml} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + + +\makeatletter +\newenvironment{42asmcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{nasm} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\lstnewenvironment{42console} { + \lstset { + extendedchars=true, + literate={✓}{{\checkmark}}1, + basicstyle=\color{lightgrey}\scriptsize\ttfamily, + backgroundcolor=\color{assholeblack}, + breaklines=true, + numberstyle=\scriptsize, + columns=flexible, + keepspaces=false, + } +}{} + +\newenvironment{42warning} + {\vspace*{1\baselineskip} + \par\begin{mdframed}[linewidth=2pt,linecolor=red]% + \begin{list}{}{\leftmargin=1cm + \labelwidth=\leftmargin}\item[\Large\ding{43}]} + {\end{list}\end{mdframed}\par \vspace*{1\baselineskip}} diff --git a/resources/latex/42-ko.cls b/resources/latex/42-ko.cls new file mode 100644 index 00000000..0368b892 --- /dev/null +++ b/resources/latex/42-ko.cls @@ -0,0 +1,887 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% 42-ja.cls +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% Authors: +% - Maxime "zaz" Montinet +% - David "Thor" Giron +% +% Contributors: +% - Mathieu Mahé +% - Gaëtan JUVIN +% - Unknown for now +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +% This class provides a layout for teaching material at 42. +% +% This class is organized this way : +% +% I - Documentation +% 1. Incompatibilites +% II - General LaTeX boilerplate +% 1. Definition +% 2. Class options and parent class +% 3. Imports +% III - Lengths and color redefinitions +% 1. Lenghts +% 2. Colors +% 3. Hyperlinks +% 4. Listings +% 5. Page layout +% 6. Roman numerals for chapters +% IV - Frontpage customization +% 1. Custom fields +% 2. Redefinition of \maketitle +% 3. Exercice number +% V - Custom helper commands +% 1. Hint/warn +% 2. Lisibility helper +% 3. Exercise headers +% 4. Reproduction from man + +%% +%% I - Documentation +%% + +%% I.1 - Incompatibilities + +% Package ulem: +% The package ulem has a lot of oddities. Using it is not always a +% good idea. If you really want to do so, you should import it with +% the [normalem] option, as such : +% \usepackage[normalem]{ulem} +% Otherwise, it overrides \emph to underline the emphasized text. So +% far so good, but underlined text is typesetted in a box, which means +% that linebreaks don't happen automatically. Since \abstract (among +% others) uses \emph, the abstract is unreadable by default. +% Please read thoroughly ulem's doc before using it. +% See also: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=underline + +%% +%% II - General LaTeX boilerplate +%% + +%% II.1 - Definition + +\NeedsTeXFormat{LaTeX2e}[1995/12/01] +\ProvidesClass{42-ko}[2019/12/26 v1.0 + LaTeX class for 42-themed documents] + +%% II.2 - Class options and parent class + +\newcommand{\summarytitle}{Summary}% + +\DeclareOption*{% + \PassOptionsToClass{\CurrentOption}{report} +} + +\ProcessOptions\relax +\LoadClass[a4paper,12pt,onecolumn]{report} + +%% II.3 - Imports +\usepackage{kotex} %%42 korean +\usepackage[top=1in,bottom=1in,left=1in,right=1in]{geometry} +\usepackage[pdftex]{graphicx} +\usepackage{url} +\usepackage{fancyhdr} +\usepackage{array} +\usepackage[table]{xcolor} +\usepackage[utf8]{inputenc} +\usepackage[T1]{fontenc} +\usepackage{lmodern} +\usepackage{listings} +\usepackage{tabularx} +\usepackage{textcomp} +\usepackage{color} +\usepackage[pdftex]{hyperref} +\usepackage{fancybox} +\usepackage{float} +\usepackage{atbeginend} % provided locally : atbeginend.sty +\usepackage{tocloft} % provided locally : tocloft.sty +\usepackage{multirow} % provided locally : multirow.sty +\usepackage[english]{babel} +\usepackage{minted} % provided locally : minted.sty +% Minted requires the Python "Pygments" librairy (http://pygments.org/). +% Pygments can be easily installed with the "easy_install" paquet manager +% from the "python-setuptools" paquet (sudo easy_install Pygments). +\usepackage{pifont,mdframed} +\usepackage{wallpaper} + +%% III - Lengths and color redefinitions + +%% III.1 - Lengths + +\AfterBegin{enumerate}{ + \itemsep10pt% +} +\AfterBegin{itemize}{ + \itemsep5pt% + \renewcommand{\labelitemi}{$\bullet$}% + \renewcommand{\labelitemii}{$\circ$}% +} + +\BeforeBegin{enumerate}{\vspace{15pt}} +\AfterEnd{enumerate}{\vspace{15pt}} + +\BeforeBegin{itemize}{\vspace{15pt}} +\AfterEnd{itemize}{\vspace{15pt}} + +\BeforeBegin{lstlisting}{\vspace{15pt}} +\AfterEnd{lstlisting}{\vspace{15pt}} + +\BeforeBegin{tabularx}{\vspace{15pt}} +\AfterEnd{tabularx}{\vspace{15pt}} + +%% III.2 - Colors + +\definecolor{nicergreen}{rgb}{0,0.502,0} +\definecolor{nicerblue}{rgb}{0,0.302,1} +\definecolor{nicerorange}{rgb}{1,0.502,0} +\definecolor{nicergrey}{rgb}{0.502,0.502,0.502} +\definecolor{nicerred}{rgb}{0.626,0,0} +\definecolor{hintbg}{rgb}{1.0,1.0,0.75} +\definecolor{warnbg}{rgb}{1.0,0.75,0.75} +\definecolor{infobg}{rgb}{0.75,0.75,1.0} +\definecolor{bibliotechbg}{RGB}{239,253,255} +\definecolor{lightgrey}{rgb}{0.95,0.95,0.95} +\definecolor{darkgrey}{rgb}{0.1,0.1,0.1} +\definecolor{assholeblack}{rgb}{0,0,0} + +%% III.3 - Hyperlinks + +\hypersetup +{ + colorlinks, +% citecolor=black, % +% filecolor=black, % + linkcolor=black, % black links + urlcolor=blue % blue URLs +} + +%% III.4 - Listings + +\lstset +{ + backgroundcolor=\color{gray!15}, + basicstyle=\small\ttfamily, + breaklines=true, + columns=fullflexible, + frame=lines, + tabsize=4, + numbers=none, %numbers=left, + numberstyle=\scriptsize\ttfamily, + numbersep=5pt, + showspaces=false, + showstringspaces=false, + showtabs=false, + breaklines=true, + upquote=true, + float +} + +%% III.5 - Page layout + +\makeatletter +\pagestyle{fancy} +\lhead{\@title} +\rhead{\@subtitle} +\cfoot{\thepage} +\makeatother + +%% III.6 - Roman chapter style + +% custom sections style + +\renewcommand{\thechapter}{\Roman{chapter}} + +% Using roman numerals makes the TOC section/subsection numbers +% overflow on the right. This adds some margin to avoid that kind of +% problems. (requires \usepackage{tocloft}) +\setlength{\cftchapnumwidth}{1.5cm} +\setlength{\cftsecnumwidth}{1.5cm} +\setlength{\cftsubsecnumwidth}{1.3cm} +\setlength{\cftsubsubsecnumwidth}{1.6cm} +\setlength{\cftaftertoctitleskip}{0.5cm} + +%% IV - Frontpage customization + +%% IV.1 - Custom fields +\makeatletter +\newcommand{\website}[1]{\def \@website {#1}} +\website{} + +\newcommand{\subtitle}[1]{\def \@subtitle {#1}} +\subtitle{} + +\newcommand{\schoollogo}[1]{\def \@schoollogo {#1}} +\schoollogo{42_logo.pdf} + +\newcommand{\summary}[1]{\def \@summary {#1}} +\summary{} + +\edef\@authors{} +\newcommand{\member}[2]{% + \protected@edef\@authors{\@authors #1 \protect\url{#2}\\} + \author{\@authors} +} +\author{} + +%% IV.2 - Redefine \maketitle + +\makeatletter +\def \maketitle { + \begin{titlepage} + \begin{center} + %\begin{figure}[t] + \includegraphics[height=8cm]{\@schoollogo} + %\end{figure} + \vskip 5em + {\huge \@title} + \vskip 2em + {\LARGE \@subtitle} + \vskip 4em + \end{center} + \begin{center} + \@author + \end{center} + \vskip 5em + \begin{center} + \emph{\summarytitle : \@summary} + \end{center} + \end{titlepage} +} +\makeatother + +\TileWallPaper{\paperwidth}{\paperheight}{back} +%% IV.3 - Exercice number + +\newcounter{exerciceCounter} +\newcommand*{\exercicenumber}{ + \ifnum\value{exerciceCounter}<10 0\fi + \arabic{exerciceCounter} +} + +\newcommand*{\startexercices}{ + \setcounter{exerciceCounter}{0} +} + +\newcommand*{\nextexercice}{ + \stepcounter{exerciceCounter} +} + +\newcounter{itemizeCounter} +\setcounter{itemizeCounter}{0} +\BeforeBegin{itemize}{ + \addtocounter{itemizeCounter}{1} +} + +\AfterEnd{itemize}{ + \addtocounter{itemizeCounter}{-1} + \ifnum\value{itemizeCounter} = 0 + \stepcounter{exerciceCounter} + \fi +} + +%% V - Custom helper commands + +%% V.1 - Hint/Warn + +% hint command + +\newcommand{\kbox}[3] +{ + \vskip 15pt + \noindent + \colorbox{#1} + { + \begin{tabular*}{0.97\textwidth}{m{4em}m{0.8\textwidth}} + \includegraphics[width=4em]{#2} + & {\ttfamily\footnotesize #3}\\ + \end{tabular*} + } + \vskip 15pt +} + +\newcommand{\hint}[1]{\kbox{hintbg}{helphint.pdf}{#1}} +\newcommand{\warn}[1]{\kbox{warnbg}{warn.pdf}{#1}} +\newcommand{\info}[1]{\kbox{infobg}{info.pdf}{#1}} + +%% V.2 Lisibility helper + +\makeatletter +\newcommand{\mso}[1]{ + \ttfamily #1 \normalfont +} + +%% V.3 Exercise headers + +\makeatletter +\newcommand{\turnindir}[1]{\def \@turnindir {#1}} +\newcommand{\daypiscine}[1]{\def \@daypiscine {#1}} +\newcommand{\extitle}[1]{\def \@extitle {#1}} +\newcommand{\exnumber}[1]{\def \@exnumber {#1}} +\newcommand{\exscore}[1]{\def \@exscore {#1}} +\newcommand{\exflags}[1][-W -Wall -Werror]{\def \@exflags {#1}} +\newcommand{\excompil}[1][gcc]{\def \@excompil {#1}} +\newcommand{\exrules}[1][n/a]{\def \@exrules {#1}} +\newcommand{\exfiles}[1]{\def \@exfiles {#1}} +\newcommand{\exnotes}[1][n/a]{\def \@exnotes {#1}} +\newcommand{\exauthorize}[1]{\def \@exauthorize {#1}} +\newcommand{\exforbidden}[1]{\def \@exforbidden {#1}} +\newcommand{\exmake}[1][No]{\def \@exmake {#1}} + +% Default values +\turnindir{} +\daypiscine{} +\extitle{} +\exnumber{} +\exscore{} +\exflags{} +\excompil{} +\exrules{} +\exfiles{} +\exnotes{} +\exauthorize{None} +\exforbidden{None} +\exmake{} + +%Header pour exercices sans rien a "rendre" +\newcommand{\makeheaderbasic} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercise : \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + +%% \multicolumn{4}{|>{\raggedright}m{15cm}|} +%% {\small Notes : \ttfamily \@exnotes } +%% \\ \hline +\end{tabularx} +%% \exnotes +\exrules +\exmake +%\exauthorize +\exforbidden{None} +\extitle{} +\exnumber{} +} + +%Header pour exercices sans code mais fichiers a rendre +\newcommand{\makeheaderfiles} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercise \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Turn-in directory : \ttfamily + $ex\@exnumber/$ } + \\ \hline + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Files to turn in : \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Allowed functions : \ttfamily \@exauthorize } + \\ \hline + +%% \multicolumn{4}{|>{\raggedright}m{15cm}|} +%% {\small Notes : \ttfamily \@exnotes } +%% \\ \hline +\end{tabularx} +%% \exnotes +\exrules +\exmake +\exauthorize{None} +\exforbidden{None} +\extitle{} +\exnumber{} +} + +%Header for exercices without turn in repository +\newcommand{\makeheaderfilesnodirectory} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercice : \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Files to turn in : \ttfamily \@exauthorize } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Authorised functions : \ttfamily \@exnotes } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Notes : \ttfamily \@exnotes } + \\ \hline +\end{tabularx} +\exnotes +\exrules +\exmake +\exauthorize{None} +\exforbidden{None} +\extitle{} +\exnumber{} +} + +%Header pour exercices sans code mais fichiers a rendre +\newcommand{\makeheaderfilesforbidden} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercise : \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Turn-in directory : \ttfamily + $ex\@exnumber/$ } + \\ \hline + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Files to turn in : \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Forbidden functions : \ttfamily \@exforbidden } + \\ \hline + +%% \multicolumn{4}{|>{\raggedright}m{15cm}|} +%% {\small Remarks : \ttfamily \@exnotes } +%% \\ \hline +\end{tabularx} +%% \exnotes +\exrules +\exmake +\exauthorize{None} +\exforbidden{None} +\extitle{} +\exnumber{} +} + +%Header pour exercices de code +\newcommand{\makeheadercode} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercise \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} + %% {\scriptsize Score : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Turn-in directory: \ttfamily + $ex\@exnumber/$ } + \\ \hline + + \multicolumn{2}{|>{\raggedright}m{7.5cm}} + {\small Compiler: \ttfamily \@excompil } & + \multicolumn{2}{|>{\raggedright}m{7.5cm}|} + {\small Compilation flags: + \ttfamily \@exflags } + \\ \hline + + \multicolumn{2}{|>{\raggedright}m{7.52cm}} + {\small Makefile: \ttfamily{\@exmake}} & + \multicolumn{2}{|>{\raggedright}m{7.5cm}|} + {Makefile rules: \ttfamily \@exrules } \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Files to turn in: \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Notes : \ttfamily \@exnotes } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Forbidden fonctions: \ttfamily \@exforbidden } + \\ \hline +\end{tabularx} +\exnotes +\exrules +\exmake +\exforbidden{None} +\extitle{} +\exnumber{} +} + + +\newcommand{\ftname}[1]{\def \@ftname {#1}} +\newcommand{\ftprototype}[1]{\def \@ftprototype {#1}} +\newcommand{\ftdesc}[1]{\def \@ftdesc {#1}} +\newcommand{\ftparams}[1]{\def \@ftparams {#1}} +\newcommand{\ftret}[1]{\def \@ftret {#1}} +\newcommand{\ftfuncts}[1]{\def \@ftfuncts {#1}} +\newcommand{\ftturnin}[1]{\def \@ftturnin {#1}} +\newcommand{\ftmakefile}[1]{\def \@ftmakefile {#1}} +\newcommand{\ftlibft}[1]{\def \@ftlibft {#1}} +\newcommand{\ftcompil}[1]{\def \@ftcompil {#1}} + +\ftname{} +\ftprototype{} +\ftdesc{} +\ftparams{} +\ftret{} +\ftfuncts{} +\ftturnin{} +\ftmakefile{} +\ftlibft{} +\ftcompil{} + + +\newcolumntype{s}{>{\hsize=.5\hsize}X} +\newcolumntype{b}{>{\hsize=1.5\hsize}X} +\newcommand{\makeheaderfct} +{ + \noindent + + \begin{tabularx}{\textwidth}{| s | b |} \hline + + \textbf{Function name} & \texttt{\@ftname} \\ \hline + \textbf{Prototype} & \texttt{\@ftprototype} \\ \hline + \textbf{Turn in files} & \texttt{\@ftturnin} \\ \hline + \textbf{Parameters} & \texttt{\@ftparams} \\ \hline + \textbf{Return value} & \texttt{\@ftret} \\ \hline + \textbf{External functs.} & \texttt{\@ftfuncts} \\ \hline + \textbf{Description} & \texttt{\@ftdesc} \\ \hline + +\end{tabularx} +} + +\newcommand{\makeheaderlib} +{ + \noindent + + \begin{tabularx}{\textwidth}{| s | b |} \hline + + \textbf{Program name} & \texttt{\@ftname} \\ \hline + \textbf{Turn in files} & \texttt{\@ftturnin} \\ \hline + \textbf{Makefile} & \texttt{\@ftmakefile} \\ \hline + \textbf{External functs.} & \texttt{\@ftfuncts} \\ \hline + \textbf{Libft authorized} & \texttt{\@ftlibft} \\ \hline + \textbf{Description} & \texttt{\@ftdesc} \\ \hline + +\end{tabularx} +} + +\newcommand{\makeheaderprg} +{ + \noindent + + \begin{tabularx}{\textwidth}{| s | b |} \hline + + \textbf{Program name} & \texttt{\@ftname} \\ \hline + \textbf{Turn in files} & \texttt{\@ftturnin} \\ \hline + \textbf{Makefile} & \texttt{\@ftmakefile} \\ \hline + \textbf{Arguments} & \texttt{\@ftparams} \\ \hline + \textbf{External functs.} & \texttt{\@ftfuncts} \\ \hline + \textbf{Libft authorized} & \texttt{\@ftlibft} \\ \hline + \textbf{Description} & \texttt{\@ftdesc} \\ \hline + +\end{tabularx} +} + + +\newcommand{\exmandatory}{Mandatory exercise} +\newcommand{\exretrovalid}{Retrovalidated exercise} +\newcommand{\exoptional}{Optional exercise} + +\newcommand{\exercice}{Exercise} + +%% V.4 Reproduction from man +\newcommand{\reproductionfromman}[1]{Reproduce the behavior of the function \texttt{#1} (man #1).} + +%% VI - Syntactic highlights + + +%% Styles: +%% ~~~~~~~ +%% * monokai: +%% This style mimics the Monokai color scheme. +%% * manni: +%% A colorful style, inspired by the terminal highlighting style. +%% * rrt: +%% Minimalistic ``rrt'' theme, based on Zap and Emacs defaults. +%% * perldoc: +%% Style similar to the style used in the perldoc code blocks. +%% * borland: +%% Style similar to the style used in the borland IDEs. +%% * colorful: +%% A colorful style, inspired by CodeRay. +%% * default: +%% The default style (inspired by Emacs 22). +%% * murphy: +%% Murphy's style from CodeRay. +%% * vs: +%% +%% * trac: +%% Port of the default trac highlighter design. +%% * tango: +%% The Crunchy default Style inspired from the color palette from the Tango Icon Theme Guidelines. +%% * fruity: +%% Pygments version of the ``native'' vim theme. +%% * autumn: +%% A colorful style, inspired by the terminal highlighting style. +%% * bw: +%% +%% * emacs: +%% The default style (inspired by Emacs 22). +%% * vim: +%% Styles somewhat like vim 7.0 +%% * pastie: +%% Style similar to the pastie default style. +%% * friendly: +%% A modern style based on the VIM pyte theme. +%% * native: +%% Pygments version of the ``native'' vim theme. + + + +%\usemintedstyle{monokai} +%\usemintedstyle{manni} +%\usemintedstyle{rrt} +%\usemintedstyle{perldoc} +%\usemintedstyle{borland} +%\usemintedstyle{colorful} +%\usemintedstyle{default} +%\usemintedstyle{murphy} +%\usemintedstyle{vs} +%\usemintedstyle{trac} +%\usemintedstyle{tango} +%\usemintedstyle{fruity} +%\usemintedstyle{autumn} +%\usemintedstyle{bw} +%\usemintedstyle{emacs} +%\usemintedstyle{vim} +%\usemintedstyle{pastie} +%\usemintedstyle{friendly} +%\usemintedstyle{native} + +\makeatletter +\newenvironment{42ccode}{% + \VerbatimEnvironment + \usemintedstyle{emacs} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{c} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42phpcode}{% + \VerbatimEnvironment + \usemintedstyle{emacs} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{html+php} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42jscode}{% + \VerbatimEnvironment + \usemintedstyle{emacs} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{js} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\definecolor{darcula-back}{RGB}{35, 37, 37} + +\makeatletter +\newenvironment{42javacode}{% + \VerbatimEnvironment + \usemintedstyle{monokai} + \minted@resetoptions + \definecolor{dark}{RGB}{35, 37, 37} + \setkeys{minted@opt}{bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{java} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42xmlcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{xml} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42yamlcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{yaml} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42cppcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{c++} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + + +\makeatletter +\newenvironment{42ocamlcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{ocaml} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + + +\makeatletter +\newenvironment{42asmcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{nasm} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\lstnewenvironment{42console} { + \lstset { + extendedchars=true, + literate={✓}{{\checkmark}}1, + basicstyle=\color{lightgrey}\scriptsize\ttfamily, + backgroundcolor=\color{assholeblack}, + breaklines=true, + numberstyle=\scriptsize, + columns=flexible, + keepspaces=false, + } +}{} + +\newenvironment{42warning} + {\vspace*{1\baselineskip} + \par\begin{mdframed}[linewidth=2pt,linecolor=red]% + \begin{list}{}{\leftmargin=1cm + \labelwidth=\leftmargin}\item[\Large\ding{43}]} + {\end{list}\end{mdframed}\par \vspace*{1\baselineskip}} diff --git a/resources/latex/42-nl.cls b/resources/latex/42-nl.cls new file mode 100644 index 00000000..6f66b43b --- /dev/null +++ b/resources/latex/42-nl.cls @@ -0,0 +1,755 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% 42.cls +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% Authors: +% - Maxime "zaz" Montinet +% - David "Thor" Giron +% +% Contributors: +% - Mathieu Mahé +% - Gaëtan JUVIN +% - Unknown for now +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +% This class provides a layout for teaching material at 42. +% +% This class is organized this way : +% +% I - Documentation +% 1. Incompatibilites +% II - General LaTeX boilerplate +% 1. Definition +% 2. Class options and parent class +% 3. Imports +% III - Lengths and color redefinitions +% 1. Lenghts +% 2. Colors +% 3. Hyperlinks +% 4. Listings +% 5. Page layout +% 6. Roman numerals for chapters +% IV - Frontpage customization +% 1. Custom fields +% 2. Redefinition of \maketitle +% 3. Exercice number +% V - Custom helper commands +% 1. Hint/warn +% 2. Lisibility helper +% 3. Exercise headers +% 4. Reproduction from man + +%% +%% I - Documentation +%% + +%% I.1 - Incompatibilities + +% Package ulem: +% The package ulem has a lot of oddities. Using it is not always a +% good idea. If you really want to do so, you should import it with +% the [normalem] option, as such : +% \usepackage[normalem]{ulem} +% Otherwise, it overrides \emph to underline the emphasized text. So +% far so good, but underlined text is typesetted in a box, which means +% that linebreaks don't happen automatically. Since \abstract (among +% others) uses \emph, the abstract is unreadable by default. +% Please read thoroughly ulem's doc before using it. +% See also: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=underline + +%% +%% II - General LaTeX boilerplate +%% + +%% II.1 - Definition + +\NeedsTeXFormat{LaTeX2e}[1995/12/01] +\ProvidesClass{42-en}[2014/08/22 v2.1 + LaTeX class for 42-themed documents] + +%% II.2 - Class options and parent class + +\newcommand{\summarytitle}{Summary}% + +\DeclareOption*{% + \PassOptionsToClass{\CurrentOption}{report} +} + +\ProcessOptions\relax +\LoadClass[a4paper,12pt,onecolumn]{report} + +%% II.3 - Imports + +\usepackage[top=1in,bottom=1in,left=1in,right=1in]{geometry} +\usepackage[pdftex]{graphicx} +\usepackage{url} +\usepackage{fancyhdr} +\usepackage{array} +\usepackage[table]{xcolor} +\usepackage[utf8]{inputenc} +\usepackage[T1]{fontenc} +\usepackage{lmodern} +\usepackage{listings} +\usepackage{tabularx} +\usepackage{textcomp} +\usepackage{color} +\usepackage[pdftex]{hyperref} +\usepackage{fancybox} +\usepackage{float} +\usepackage{atbeginend} % provided locally : atbeginend.sty +\usepackage{tocloft} % provided locally : tocloft.sty +\usepackage{multirow} % provided locally : multirow.sty +\usepackage[dutch]{babel} +\usepackage{minted} % provided locally : minted.sty +% Minted requires the Python "Pygments" librairy (http://pygments.org/). +% Pygments can be easily installed with the "easy_install" paquet manager +% from the "python-setuptools" paquet (sudo easy_install Pygments). +\usepackage{pifont,mdframed} +\usepackage{wallpaper} + +%% III - Lengths and color redefinitions + +%% III.1 - Lengths + +\AfterBegin{enumerate}{ + \itemsep10pt% +} +\AfterBegin{itemize}{ + \itemsep10pt% + \renewcommand{\labelitemi}{$\bullet$}% + \renewcommand{\labelitemii}{$\circ$}% +} + +\BeforeBegin{enumerate}{\vspace{15pt}} +\AfterEnd{enumerate}{\vspace{15pt}} + +\BeforeBegin{itemize}{\vspace{15pt}} +\AfterEnd{itemize}{\vspace{15pt}} + +\BeforeBegin{lstlisting}{\vspace{15pt}} +\AfterEnd{lstlisting}{\vspace{15pt}} + +\BeforeBegin{tabularx}{\vspace{15pt}} +\AfterEnd{tabularx}{\vspace{15pt}} + +%% III.2 - Colors + +\definecolor{nicergreen}{rgb}{0,0.502,0} +\definecolor{nicerblue}{rgb}{0,0.302,1} +\definecolor{nicerorange}{rgb}{1,0.502,0} +\definecolor{nicergrey}{rgb}{0.502,0.502,0.502} +\definecolor{nicerred}{rgb}{0.626,0,0} +\definecolor{hintbg}{rgb}{1.0,1.0,0.75} +\definecolor{warnbg}{rgb}{1.0,0.75,0.75} +\definecolor{infobg}{rgb}{0.75,0.75,1.0} +\definecolor{bibliotechbg}{RGB}{239,253,255} +\definecolor{lightgrey}{rgb}{0.95,0.95,0.95} +\definecolor{darkgrey}{rgb}{0.1,0.1,0.1} +\definecolor{assholeblack}{rgb}{0,0,0} + +%% III.3 - Hyperlinks + +\hypersetup +{ + colorlinks, +% citecolor=black, % +% filecolor=black, % + linkcolor=black, % black links + urlcolor=blue % blue URLs +} + +%% III.4 - Listings + +\lstset +{ + backgroundcolor=\color{gray!15}, + basicstyle=\small\ttfamily, + breaklines=true, + columns=fullflexible, + frame=lines, + tabsize=4, + numbers=none, %numbers=left, + numberstyle=\scriptsize\ttfamily, + numbersep=5pt, + showspaces=false, + showstringspaces=false, + showtabs=false, + breaklines=true, + upquote=true, + float +} + +%% III.5 - Page layout + +\makeatletter +\pagestyle{fancy} +\lhead{\@title} +\rhead{\@subtitle} +\cfoot{\thepage} +\makeatother + +%% III.6 - Roman chapter style + +% custom sections style + +\renewcommand{\thechapter}{\Roman{chapter}} + +% Using roman numerals makes the TOC section/subsection numbers +% overflow on the right. This adds some margin to avoid that kind of +% problems. (requires \usepackage{tocloft}) +\setlength{\cftchapnumwidth}{1.5cm} +\setlength{\cftsecnumwidth}{1.5cm} +\setlength{\cftsubsecnumwidth}{1.3cm} +\setlength{\cftsubsubsecnumwidth}{1.6cm} +\setlength{\cftaftertoctitleskip}{0.5cm} + +%% IV - Frontpage customization + +%% IV.1 - Custom fields +\makeatletter +\newcommand{\website}[1]{\def \@website {#1}} +\website{} + +\newcommand{\subtitle}[1]{\def \@subtitle {#1}} +\subtitle{} + +\newcommand{\schoollogo}[1]{\def \@schoollogo {#1}} +\schoollogo{42_logo.pdf} + +\newcommand{\summary}[1]{\def \@summary {#1}} +\summary{} + +\edef\@authors{} +\newcommand{\member}[2]{% + \protected@edef\@authors{\@authors #1 \protect\url{#2}\\} + \author{\@authors} +} +\author{} + +%% IV.2 - Redefine \maketitle + +\makeatletter +\def \maketitle { + \begin{titlepage} + \begin{center} + %\begin{figure}[t] + \includegraphics[height=8cm]{\@schoollogo} + %\end{figure} + \vskip 5em + {\huge \@title} + \vskip 2em + {\LARGE \@subtitle} + \vskip 4em + \end{center} + \begin{center} + \@author + \end{center} + \vskip 5em + \begin{center} + \emph{\summarytitle : \@summary} + \end{center} + \end{titlepage} +} +\makeatother + +\TileWallPaper{\paperwidth}{\paperheight}{back} +%% IV.3 - Exercice number + +\newcounter{exerciceCounter} +\newcommand*{\exercicenumber}{ + \ifnum\value{exerciceCounter}<10 0\fi + \arabic{exerciceCounter} +} + +\newcommand*{\startexercices}{ + \setcounter{exerciceCounter}{0} +} + +\newcommand*{\nextexercice}{ + \stepcounter{exerciceCounter} +} + +\newcounter{itemizeCounter} +\setcounter{itemizeCounter}{0} +\BeforeBegin{itemize}{ + \addtocounter{itemizeCounter}{1} +} + +\AfterEnd{itemize}{ + \addtocounter{itemizeCounter}{-1} + \ifnum\value{itemizeCounter} = 0 + \stepcounter{exerciceCounter} + \fi +} + +%% V - Custom helper commands + +%% V.1 - Hint/Warn + +% hint command + +\newcommand{\kbox}[3] +{ + \vskip 15pt + \noindent + \colorbox{#1} + { + \begin{tabular*}{0.97\textwidth}{m{4em}m{0.8\textwidth}} + \includegraphics[width=4em]{#2} + & {\ttfamily\footnotesize #3}\\ + \end{tabular*} + } + \vskip 15pt +} + +\newcommand{\hint}[1]{\kbox{hintbg}{helphint.pdf}{#1}} +\newcommand{\warn}[1]{\kbox{warnbg}{warn.pdf}{#1}} +\newcommand{\info}[1]{\kbox{infobg}{info.pdf}{#1}} + +%% V.2 Lisibility helper + +\makeatletter +\newcommand{\mso}[1]{ + \ttfamily #1 \normalfont +} + +%% V.3 Exercise headers + +\makeatletter +\newcommand{\turnindir}[1]{\def \@turnindir {#1}} +\newcommand{\daypiscine}[1]{\def \@daypiscine {#1}} +\newcommand{\extitle}[1]{\def \@extitle {#1}} +\newcommand{\exnumber}[1]{\def \@exnumber {#1}} +\newcommand{\exscore}[1]{\def \@exscore {#1}} +\newcommand{\exflags}[1][-W -Wall -Werror]{\def \@exflags {#1}} +\newcommand{\excompil}[1][gcc]{\def \@excompil {#1}} +\newcommand{\exrules}[1][n/a]{\def \@exrules {#1}} +\newcommand{\exfiles}[1]{\def \@exfiles {#1}} +\newcommand{\exnotes}[1][n/a]{\def \@exnotes {#1}} +\newcommand{\exauthorize}[1]{\def \@exauthorize {#1}} +\newcommand{\exforbidden}[1]{\def \@exforbidden {#1}} +\newcommand{\exmake}[1][No]{\def \@exmake {#1}} + + +% Default values +\turnindir{} +\daypiscine{} +\extitle{} +\exnumber{} +\exscore{} +\exflags{} +\excompil{} +\exrules{} +\exfiles{} +\exnotes{} +\exauthorize{None} +\exforbidden{None} +\exmake{} + +%Header pour exercices sans rien a "rendre" +\newcommand{\makeheaderbasic} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Oefening : \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Aantekeningen : \ttfamily \@exnotes } + \\ \hline +\end{tabularx} +\exnotes +\exrules +\exmake +\exauthorize{None} +\exforbidden{None} +\extitle{} +\exnumber{} +} + +%Header pour exercices sans code mais fichiers a rendre +\newcommand{\makeheaderfiles} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Oefening \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Vergaarbak map : \ttfamily + $ex\@exnumber/$ } + \\ \hline + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Files to turn in : \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Allowed functions : \ttfamily \@exauthorize } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Aantekeningen : \ttfamily \@exnotes } + \\ \hline +\end{tabularx} +\exnotes +\exrules +\exmake +\exauthorize{None} +\exforbidden{None} +\extitle{} +\exnumber{} +} + +%Header pour exercices sans code mais fichiers a rendre +\newcommand{\makeheaderfilesforbidden} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercise \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Turn-in directory : \ttfamily + $ex\@exnumber/$ } + \\ \hline + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Files to turn in : \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Forbidden functions : \ttfamily \@exforbidden } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Remarks : \ttfamily \@exnotes } + \\ \hline +\end{tabularx} +\exnotes +\exrules +\exmake +\exauthorize{None} +\exforbidden{None} +\extitle{} +\exnumber{} +} + +%Header pour exercices de code +\newcommand{\makeheadercode} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercise \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} + %% {\scriptsize Score : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Turn-in directory: \ttfamily + $ex\@exnumber/$ } + \\ \hline + + \multicolumn{2}{|>{\raggedright}m{7.5cm}} + {\small Compiler: \ttfamily \@excompil } & + \multicolumn{2}{|>{\raggedright}m{7.5cm}|} + {\small Compilation flags: + \ttfamily \@exflags } + \\ \hline + + \multicolumn{2}{|>{\raggedright}m{7.52cm}} + {\small Makefile: \ttfamily{\@exmake}} & + \multicolumn{2}{|>{\raggedright}m{7.5cm}|} + {Makefile rules: \ttfamily \@exrules } \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Files to turn in: \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Notes : \ttfamily \@exnotes } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Forbidden fonctions: \ttfamily \@exforbidden } + \\ \hline +\end{tabularx} +\exnotes +\exrules +\exmake +\exforbidden{None} +\exauthorize{None} +\extitle{} +\exnumber{} +} + +\newcommand{\exmandatory}{Mandatory exercise} +\newcommand{\exretrovalid}{Retrovalidated exercise} +\newcommand{\exoptional}{Optional exercise} + +\newcommand{\exercice}{Exercise} + +%% V.4 Reproduction from man +\newcommand{\reproductionfromman}[1]{Reproduce the behavior of the function \texttt{#1} (man #1).} + +%% VI - Syntactic highlights + + +%% Styles: +%% ~~~~~~~ +%% * monokai: +%% This style mimics the Monokai color scheme. +%% * manni: +%% A colorful style, inspired by the terminal highlighting style. +%% * rrt: +%% Minimalistic ``rrt'' theme, based on Zap and Emacs defaults. +%% * perldoc: +%% Style similar to the style used in the perldoc code blocks. +%% * borland: +%% Style similar to the style used in the borland IDEs. +%% * colorful: +%% A colorful style, inspired by CodeRay. +%% * default: +%% The default style (inspired by Emacs 22). +%% * murphy: +%% Murphy's style from CodeRay. +%% * vs: +%% +%% * trac: +%% Port of the default trac highlighter design. +%% * tango: +%% The Crunchy default Style inspired from the color palette from the Tango Icon Theme Guidelines. +%% * fruity: +%% Pygments version of the ``native'' vim theme. +%% * autumn: +%% A colorful style, inspired by the terminal highlighting style. +%% * bw: +%% +%% * emacs: +%% The default style (inspired by Emacs 22). +%% * vim: +%% Styles somewhat like vim 7.0 +%% * pastie: +%% Style similar to the pastie default style. +%% * friendly: +%% A modern style based on the VIM pyte theme. +%% * native: +%% Pygments version of the ``native'' vim theme. + + + +%\usemintedstyle{monokai} +%\usemintedstyle{manni} +%\usemintedstyle{rrt} +%\usemintedstyle{perldoc} +%\usemintedstyle{borland} +%\usemintedstyle{colorful} +%\usemintedstyle{default} +%\usemintedstyle{murphy} +%\usemintedstyle{vs} +%\usemintedstyle{trac} +%\usemintedstyle{tango} +%\usemintedstyle{fruity} +%\usemintedstyle{autumn} +%\usemintedstyle{bw} +%\usemintedstyle{emacs} +%\usemintedstyle{vim} +%\usemintedstyle{pastie} +%\usemintedstyle{friendly} +%\usemintedstyle{native} + +\makeatletter +\newenvironment{42ccode}{% + \VerbatimEnvironment + \usemintedstyle{emacs} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{c} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42phpcode}{% + \VerbatimEnvironment + \usemintedstyle{emacs} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{html+php} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42yamlcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{yaml} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\definecolor{darcula-back}{RGB}{35, 37, 37} + +\makeatletter +\newenvironment{42javacode}{% + \VerbatimEnvironment + \usemintedstyle{monokai} + \minted@resetoptions + \definecolor{dark}{RGB}{35, 37, 37} + \setkeys{minted@opt}{bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{java} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42xmlcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{xml} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42cppcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{c++} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + + +\makeatletter +\newenvironment{42ocamlcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{ocaml} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + + +\makeatletter +\newenvironment{42asmcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{nasm} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\lstnewenvironment{42console} { + \lstset { + basicstyle=\color{lightgrey}\scriptsize\ttfamily, + backgroundcolor=\color{assholeblack}, + breaklines=true, + numberstyle=\scriptsize, + columns=flexible, + keepspaces=true, + } +}{} + +\newenvironment{42warning} + {\vspace*{1\baselineskip} + \par\begin{mdframed}[linewidth=2pt,linecolor=red]% + \begin{list}{}{\leftmargin=1cm + \labelwidth=\leftmargin}\item[\Large\ding{43}]} + {\end{list}\end{mdframed}\par \vspace*{1\baselineskip}} diff --git a/resources/latex/42-pt.cls b/resources/latex/42-pt.cls new file mode 100644 index 00000000..a4c429ec --- /dev/null +++ b/resources/latex/42-pt.cls @@ -0,0 +1,887 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% 42-pt.cls +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% Autores: +% - Maxime "zaz" Montinet +% - David "Thor" Giron +% +% Colaboradores: +% - Mathieu Mahé +% - Gaëtan JUVIN +% - Desconhecido por enquanto +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +% Esta classe fornece o layout do material de ensino na 42. +% +% Esta classe é organizada como segue: +% +% I - Documentação +% 1. Incompatibilidades +% II - Clichês gerais LaTeX +% 1. Definição +% 2. Opções de classe e classe pai +% 3. Importações +% III - Comprimentos e redefinições de cores +% 1. Comprimentos +% 2. Cores +% 3. Hiperlinks +% 4. Listagens +% 5. Layout da página +% 6. Numerais romanos para os capítulos +% IV - Personalização da primeira página +% 1. Campos personalizados +% 2. Redefinição de \maketitle +% 3. Número do exercício +% V - Comandos de auxiliar personalizados +% 1. Dica/aviso +% 2. Auxiliar de legibilidade +% 3. Cabeçalho dos exercícios +% 4. Reprodução de man + +%% +%% I - Documentação +%% + +%% I.1 - Incompatibilidades + +% Pacote ulem: +% O pacote ulem tem muitas peculiaridades. Nem sempre é uma +% boa ideia usá-lo. Se quiser mesmo usá-lo, você deve importá-lo com +% a opção [normalem], como: +% \usepackage[normalem]{ulem} +% Se não fizer assim, ele substituirá o \emph para sublinhar o texto destacado. Até +% aqui, tudo bem, mas o texto sublinhado é composto em uma caixa, o que significa +% que as quebras de linha não acontecem automaticamente. Uma vez que \abstract (entre +% outros) usa \emph, o abstract fica ilegível por padrão. +% Leia o doc do ulem cuidadosamente antes de usá-lo. +% Veja também: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=underline + +%% +%% II - Clichês gerais LaTeX +%% + +%% II.1 - Definição + +\NeedsTeXFormat{LaTeX2e}[1995/12/01] +\ProvidesClass{42-pt}[2010/07/15 v2.0 + Classe LaTeX para documentos com o tema da 42] + +%% II.2 - Opções de classe e classe pai + +\newcommand{\summarytitle}{Sumário}% + +\DeclareOption*{% + \PassOptionsToClass{\CurrentOption}{report} +} + +\ProcessOptions\relax +\LoadClass[a4paper,12pt,onecolumn]{report} + +%% II.3 - Importações + +\usepackage[top=1in,bottom=1in,left=1in,right=1in]{geometry} +\usepackage[pdftex]{graphicx} +\usepackage{url} +\usepackage{fancyhdr} +\usepackage{array} +\usepackage[table]{xcolor} +\usepackage[utf8]{inputenc} +\usepackage[T1]{fontenc} +\usepackage{lmodern} +\usepackage{listings} +\usepackage{tabularx} +\usepackage{textcomp} +\usepackage{color} +\usepackage[pdftex]{hyperref} +\usepackage{fancybox} +\usepackage{float} +\usepackage{atbeginend} % fornecido localmente : atbeginend.sty +\usepackage{tocloft} % fornecido localmente : tocloft.sty +\usepackage{multirow} % fornecido localmente : multirow.sty +\usepackage[portuguese]{babel} +\usepackage{minted} % fornecido localmente : minted.sty +% Minted exige uma biblioteca "Pygments" Python (http://pygments.org/). +% Pygments pode ser instalado com facilidade com o gerenciador de pacotes "easy_install" +% do pacote "python-setuptools" (sudo easy_install Pygments). +\usepackage{pifont,mdframed} +\usepackage{wallpaper} + +%% III - Comprimentos e redefinições de cores + +%% III.1 - Comprimentos + +\AfterBegin{enumerate}{ + \itemsep10pt% +} +\AfterBegin{itemize}{ + \itemsep10pt% + \renewcommand{\labelitemi}{$\bullet$}% + \renewcommand{\labelitemii}{$\circ$}% +} + +\BeforeBegin{enumerate}{\vspace{15pt}} +\AfterEnd{enumerate}{\vspace{15pt}} + +\BeforeBegin{itemize}{\vspace{15pt}} +\AfterEnd{itemize}{\vspace{15pt}} + +\BeforeBegin{lstlisting}{\vspace{15pt}} +\AfterEnd{lstlisting}{\vspace{15pt}} + +\BeforeBegin{tabularx}{\vspace{15pt}} +\AfterEnd{tabularx}{\vspace{15pt}} + +%% III.2 - Cores + +\definecolor{nicergreen}{rgb}{0,0.502,0} +\definecolor{nicerblue}{rgb}{0,0.302,1} +\definecolor{nicerorange}{rgb}{1,0.502,0} +\definecolor{nicergrey}{rgb}{0.502,0.502,0.502} +\definecolor{nicerred}{rgb}{0.626,0,0} +\definecolor{hintbg}{rgb}{1.0,1.0,0.75} +\definecolor{warnbg}{rgb}{1.0,0.75,0.75} +\definecolor{infobg}{rgb}{0.75,0.75,1.0} +\definecolor{bibliotechbg}{RGB}{239,253,255} +\definecolor{lightgrey}{rgb}{0.95,0.95,0.95} +\definecolor{darkgrey}{rgb}{0.1,0.1,0.1} +\definecolor{assholeblack}{rgb}{0,0,0} + +%% III.3 - Hiperlinks + +\hypersetup +{ + colorlinks, +% citecolor=black, % +% filecolor=black, % + linkcolor=black, % links em preto + urlcolor=blue % URLs em azul +} + +%% III.4 - Listagens + +\lstset +{ + backgroundcolor=\color{gray!15}, + basicstyle=\small\ttfamily, + breaklines=true, + columns=fullflexible, + frame=lines, + tabsize=4, + numbers=none, %numbers=left, + numberstyle=\scriptsize\ttfamily, + numbersep=5pt, + showspaces=false, + showstringspaces=false, + showtabs=false, + breaklines=true, + upquote=true, + float +} + +%% III.5 - Layout da página + +\makeatletter +\pagestyle{fancy} +\lhead{\@title} +\rhead{\@subtitle} +\cfoot{\thepage} +\makeatother + +%% III.6 - Estilo de capítulo romano + +% estilo de seções personalizadas + +\renewcommand{\thechapter}{\Roman{chapter}} + +% Usar numerais romanos faz os números da seção/subseção TOC +% estourarem à direita. Isto adiciona margem para evitar esse tipo de +% problema. (exige \usepackage{tocloft}) +\setlength{\cftchapnumwidth}{1.5cm} +\setlength{\cftsecnumwidth}{1.5cm} +\setlength{\cftsubsecnumwidth}{1.3cm} +\setlength{\cftsubsubsecnumwidth}{1.6cm} +\setlength{\cftaftertoctitleskip}{0.5cm} + +%% IV - Personalização da primeira página + +%% IV.1 - Campos personalizados +\makeatletter +\newcommand{\website}[1]{\def \@website {#1}} +\website{} + +\newcommand{\subtitle}[1]{\def \@subtitle {#1}} +\subtitle{} + +\newcommand{\schoollogo}[1]{\def \@schoollogo {#1}} +\schoollogo{42_logo.pdf} + +\newcommand{\summary}[1]{\def \@summary {#1}} +\summary{} + +\edef\@authors{} +\newcommand{\member}[2]{% + \protected@edef\@authors{\@authors #1 \protect\url{#2}\\} + \author{\@authors} +} +\author{} + +%% IV.2 - Redefinir \maketitle + +\makeatletter +\def \maketitle { + \begin{titlepage} + \begin{center} + %\begin{figure}[t] + \includegraphics[height=8cm]{\@schoollogo} + %\end{figure} + \vskip 5em + {\huge \@title} + \vskip 2em + {\LARGE \@subtitle} + \vskip 4em + \end{center} + \begin{center} + \@author + \end{center} + \vskip 5em + \begin{center} + \emph{\summarytitle : \@summary} + \end{center} + \end{titlepage} +} +\makeatother + +\TileWallPaper{\paperwidth}{\paperheight}{back} +%% IV.3 - Número do exercício + +\newcounter{exerciceCounter} +\newcommand*{\exercicenumber}{ + \ifnum\value{exerciceCounter}<10 0\fi + \arabic{exerciceCounter} +} + +\newcommand*{\startexercices}{ + \setcounter{exerciceCounter}{0} +} + +\newcommand*{\nextexercice}{ + \stepcounter{exerciceCounter} +} + +\newcounter{itemizeCounter} +\setcounter{itemizeCounter}{0} +\BeforeBegin{itemize}{ + \addtocounter{itemizeCounter}{1} +} + +\AfterEnd{itemize}{ + \addtocounter{itemizeCounter}{-1} + \ifnum\value{itemizeCounter} = 0 + \stepcounter{exerciceCounter} + \fi +} + +%% V - Comandos de auxiliar personalizados + +%% V.1 - Dica/Aviso + +% comando de dica + +\newcommand{\kbox}[3] +{ + \vskip 15pt + \noindent + \colorbox{#1} + { + \begin{tabular*}{0.97\textwidth}{m{4em}m{0.8\textwidth}} + \includegraphics[width=4em]{#2} + & {\ttfamily\footnotesize #3}\\ + \end{tabular*} + } + \vskip 15pt +} + +\newcommand{\hint}[1]{\kbox{hintbg}{helphint.pdf}{#1}} +\newcommand{\warn}[1]{\kbox{warnbg}{warn.pdf}{#1}} +\newcommand{\info}[1]{\kbox{infobg}{info.pdf}{#1}} + +%% V.2 Auxiliar de legibilidade + +\makeatletter +\newcommand{\mso}[1]{ + \ttfamily #1 \normalfont +} + +%% V.3 Cabeçalhos de exercícios + +\makeatletter +\newcommand{\turnindir}[1]{\def \@turnindir {#1}} +\newcommand{\daypiscine}[1]{\def \@daypiscine {#1}} +\newcommand{\extitle}[1]{\def \@extitle {#1}} +\newcommand{\exnumber}[1]{\def \@exnumber {#1}} +\newcommand{\exscore}[1]{\def \@exscore {#1}} +\newcommand{\exflags}[1][-W -Wall -Werror]{\def \@exflags {#1}} +\newcommand{\excompil}[1][gcc]{\def \@excompil {#1}} +\newcommand{\exrules}[1][n/a]{\def \@exrules {#1}} +\newcommand{\exfiles}[1]{\def \@exfiles {#1}} +\newcommand{\exnotes}[1][n/a]{\def \@exnotes {#1}} +\newcommand{\exauthorize}[1]{\def \@exauthorize {#1}} +\newcommand{\exforbidden}[1]{\def \@exforbidden {#1}} +\newcommand{\exmake}[1][Non]{\def \@exmake {#1}} + +% Valores padrão +\turnindir{} +\daypiscine{} +\extitle{} +\exnumber{} +\exscore{} +\exflags{} +\excompil{} +\exrules{} +\exfiles{} +\exnotes{} +\exauthorize{Nenhuma} +\exforbidden{Nenhuma} +\exmake{} + +%Cabeçalho para exercícios sem nada para "entregar" +\newcommand{\makeheaderbasic} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercice : \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + +%% \multicolumn{4}{|>{\raggedright}m{15cm}|} +%% {\small Notas: \ttfamily \@exnotes } +%% \\ \hline +\end{tabularx} +%% \exnotes +\exrules +\exmake +%\exauthorize +\exforbidden{Nenhuma} +\extitle{} +\exnumber{} +} + +%Cabeçalho para exercícios sem código mas com arquivos para entregar +\newcommand{\makeheaderfiles} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercício : \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Pasta de entrega : \ttfamily + $ex\@exnumber/$ } + \\ \hline + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Arquivos para entregar : \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Funções autorizadas : \ttfamily \@exauthorize } + \\ \hline + +%% \multicolumn{4}{|>{\raggedright}m{15cm}|} +%% {\small Notas : \ttfamily \@exnotes } +%% \\ \hline +\end{tabularx} +%% \exnotes +\exrules +\exmake +\exauthorize{Nenhuma} +\exforbidden{Nenhuma} +\extitle{} +\exnumber{} +} + +%Cabeçalho para exercícios sem pasta de entrega +\newcommand{\makeheaderfilesnodirectory} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercício: \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Arquivos para entregar : \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Funções autorizadas : \ttfamily \@exauthorize } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Notas: \ttfamily \@exnotes } + \\ \hline +\end{tabularx} +\exnotes +\exrules +\exmake +\exauthorize{Nenhuma} +\exforbidden{Nenhuma} +\extitle{} +\exnumber{} +} + +%Cabeçalho para exercícios sem código mas com arquivos para entregar +\newcommand{\makeheaderfilesforbidden} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercice : \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Pasta de entrega : \ttfamily + $ex\@exnumber/$ } + \\ \hline + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Arquivos para entregar : \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Funções não permitidas : \ttfamily \@exforbidden } + \\ \hline + +%% \multicolumn{4}{|>{\raggedright}m{15cm}|} +%% {\small Notas : \ttfamily \@exnotes } +%% \\ \hline +\end{tabularx} +%% \exnotes +\exrules +\exmake +\exauthorize{Nenhuma} +\exforbidden{Nenhuma} +\extitle{} +\exnumber{} +} + + +%Cabeçalho para exercícios de código +\newcommand{\makeheadercode} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercício : \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} + %% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Pasta de entrega: \ttfamily + $ex\@exnumber/$ } + \\ \hline + + \multicolumn{2}{|>{\raggedright}m{7.5cm}} + {\small Compilador : \ttfamily \@excompil } & + \multicolumn{2}{|>{\raggedright}m{7.5cm}|} + {\small Sinalização de compilação: + \ttfamily \@exflags } + \\ \hline + + \multicolumn{2}{|>{\raggedright}m{7.52cm}} + {\small Makefile : \ttfamily{\@exmake}} & + \multicolumn{2}{|>{\raggedright}m{7.5cm}|} + {R\`{e}gles : \ttfamily \@exrules } \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Arquivos para entregar : \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Notas: \ttfamily \@exnotes } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Funções não permitidas : \ttfamily \@exforbidden } + \\ \hline +\end{tabularx} +\exnotes +\exrules +\exmake +\exforbidden{Nenhuma} +\extitle{} +\exnumber{} +} + +\newcommand{\ftname}[1]{\def \@ftname {#1}} +\newcommand{\ftprototype}[1]{\def \@ftprototype {#1}} +\newcommand{\ftdesc}[1]{\def \@ftdesc {#1}} +\newcommand{\ftparams}[1]{\def \@ftparams {#1}} +\newcommand{\ftret}[1]{\def \@ftret {#1}} +\newcommand{\ftfuncts}[1]{\def \@ftfuncts {#1}} +\newcommand{\ftturnin}[1]{\def \@ftturnin {#1}} +\newcommand{\ftmakefile}[1]{\def \@ftmakefile {#1}} +\newcommand{\ftlibft}[1]{\def \@ftlibft {#1}} +\newcommand{\ftcompil}[1]{\def \@ftcompil {#1}} + +\ftname{} +\ftprototype{} +\ftdesc{} +\ftparams{} +\ftret{} +\ftfuncts{} +\ftturnin{} +\ftmakefile{} +\ftlibft{} +\ftcompil{} + + +\newcolumntype{s}{>{\hsize=.5\hsize}X} +\newcolumntype{b}{>{\hsize=1.5\hsize}X} +\newcommand{\makeheaderfct} +{ + \noindent + + \begin{tabularx}{\textwidth}{| s | b |} \hline + + \textbf{Nome da função} & \texttt{\@ftname} \\ \hline + \textbf{Protótipo} & \texttt{\@ftprototype} \\ \hline + \textbf{Arquivos de entrega} & \texttt{\@ftturnin} \\ \hline + \textbf{Parâmetros} & \texttt{\@ftparams} \\ \hline + \textbf{Valor de retorno} & \texttt{\@ftret} \\ \hline + \textbf{Funções externas autorizadas} & \texttt{\@ftfuncts} \\ \hline + \textbf{Descrição} & \texttt{\@ftdesc} \\ \hline + +\end{tabularx} +} + +\newcommand{\makeheaderlib} +{ + \noindent + + \begin{tabularx}{\textwidth}{| s | b |} \hline + + \textbf{Nome do programa} & \texttt{\@ftname} \\ \hline + \textbf{Arquivos de entrega} & \texttt{\@ftturnin} \\ \hline + \textbf{Makefile} & \texttt{\@ftmakefile} \\ \hline + \textbf{Funções externas autorizadas} & \texttt{\@ftfuncts} \\ \hline + \textbf{Libft autorizado} & \texttt{\@ftlibft} \\ \hline + \textbf{Descrição} & \texttt{\@ftdesc} \\ \hline + +\end{tabularx} +} + +\newcommand{\makeheaderprg} +{ + \noindent + + \begin{tabularx}{\textwidth}{| s | b |} \hline + + \textbf{Nome do programa} & \texttt{\@ftname} \\ \hline + \textbf{Arquivos de entrega} & \texttt{\@ftturnin} \\ \hline + \textbf{Makefile} & \texttt{\@ftmakefile} \\ \hline + \textbf{Argumentos} & \texttt{\@ftparams} \\ \hline + \textbf{Funções externas autorizadas} & \texttt{\@ftfuncts} \\ \hline + \textbf{Libft autorizado} & \texttt{\@ftlibft} \\ \hline + \textbf{Descrição} & \texttt{\@ftdesc} \\ \hline + +\end{tabularx} +} + + +\newcommand{\exmandatory}{Exercício obrigatório} +\newcommand{\exretrovalid}{Exercício retrovalidável} +\newcommand{\exoptional}{Exercício bônus} + +\newcommand{\exercice}{Exercício} + +%% V.4 Reprodução de man +\newcommand{\reproductionfromman}[1]{Reproduzir de forma idêntica o funcionamento da função \texttt{#1} (man #1).} + +%% VI - Destaques sintáticos + + +%% Estilos: +%% ~~~~~~~ +%% * monokai: +%% Este estilo imita o esquema de cores Monokai. +%% * manni: +%% Um estilo colorido, inspirado pelo estilo de destaque terminal. +%% * rrt: +%% Tema "rrt'' minimalista, baseado nos padrões Zap e Emacs. +%% * perldoc: +%% Estilo semelhante ao estilo usado nos blocos de código perldoc. +%% * borland: +%% Estilo semelhante ao estilo usado nos IDEs do borland. +%% * colorful: +%% Um estilo colorido inspirado em CodeRay. +%% * default: +%% O estilo padrão (inspirado em Emacs 22). +%% * murphy: +%% Estilo do Murphy do CodeRay. +%% * vs: +%% +%% * trac: +%% Porta do design do marca-texto trac padrão. +%% * tango: +%% O estilo padrão Crunchy inspirado na paleta de cores das diretrizes do tema do ícone Tango. +%% * fruity: +%% Versão de Pygments do tema "nativo'' vim. +%% * autumn: +%% Um estilo colorido, inspirado pelo estilo de destaque terminal. +%% * bw: +%% +%% * emacs: +%% O estilo padrão (inspirado em Emacs 22). +%% * vim: +%% Estilos parecidos com vim 7.0 +%% * pastie: +%% Estilo semelhante ao estilo padrão pastie. +%% * friendly: +%% Estilo moderno baseado no tema VIM pyte. +%% * native: +%% Versão de Pygments do tema "nativo'' vim. + + + +%\usemintedstyle{monokai} +%\usemintedstyle{manni} +%\usemintedstyle{rrt} +%\usemintedstyle{perldoc} +%\usemintedstyle{borland} +%\usemintedstyle{colorful} +%\usemintedstyle{default} +%\usemintedstyle{murphy} +%\usemintedstyle{vs} +%\usemintedstyle{trac} +%\usemintedstyle{tango} +%\usemintedstyle{fruity} +%\usemintedstyle{autumn} +%\usemintedstyle{bw} +%\usemintedstyle{emacs} +%\usemintedstyle{vim} +%\usemintedstyle{pastie} +%\usemintedstyle{friendly} +%\usemintedstyle{native} + +\makeatletter +\newenvironment{42ccode}{% + \VerbatimEnvironment + \usemintedstyle{emacs} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{c} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42phpcode}{% + \VerbatimEnvironment + \usemintedstyle{emacs} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{html+php} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42jscode}{% + \VerbatimEnvironment + \usemintedstyle{emacs} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{js} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\definecolor{darcula-back}{RGB}{35, 37, 37} + +\makeatletter +\newenvironment{42javacode}{% + \VerbatimEnvironment + \usemintedstyle{monokai} + \minted@resetoptions + \definecolor{dark}{RGB}{35, 37, 37} + \setkeys{minted@opt}{bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{java} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42xmlcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{xml} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42yamlcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{yaml} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42cppcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{c++} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + + +\makeatletter +\newenvironment{42ocamlcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{ocaml} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + + +\makeatletter +\newenvironment{42asmcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{nasm} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\lstnewenvironment{42console} { + \lstset { + extendedchars=true, + literate={✓}{{\checkmark}}1, + basicstyle=\color{lightgrey}\scriptsize\ttfamily, + backgroundcolor=\color{assholeblack}, + breaklines=true, + numberstyle=\scriptsize, + columns=flexible, + keepspaces=false, + } +}{} + +\newenvironment{42warning} + {\vspace*{1\baselineskip} + \par\begin{mdframed}[linewidth=2pt,linecolor=red]% + \begin{list}{}{\leftmargin=1cm + \labelwidth=\leftmargin}\item[\Large\ding{43}]} + {\end{list}\end{mdframed}\par \vspace*{1\baselineskip}} diff --git a/resources/latex/42-ro.cls b/resources/latex/42-ro.cls new file mode 100644 index 00000000..ece65d3b --- /dev/null +++ b/resources/latex/42-ro.cls @@ -0,0 +1,689 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% 42-ro.cls +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% Authors: +% - Maxime "zaz" Montinet +% - David "Thor" Giron +% +% Contributors: +% - Mathieu Mahé +% - Gaëtan JUVIN +% - Unknown for now +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +% This class provides a layout for teaching material at 42. +% +% This class is organized this way : +% +% I - Documentation +% 1. Incompatibilites +% II - General LaTeX boilerplate +% 1. Definition +% 2. Class options and parent class +% 3. Imports +% III - Lengths and color redefinitions +% 1. Lenghts +% 2. Colors +% 3. Hyperlinks +% 4. Listings +% 5. Page layout +% 6. Roman numerals for chapters +% IV - Frontpage customization +% 1. Custom fields +% 2. Redefinition of \maketitle +% 3. Exercice number +% V - Custom helper commands +% 1. Hint/warn +% 2. Lisibility helper +% 3. Exercise headers +% 4. Reproduction from man + +%% +%% I - Documentation +%% + +%% I.1 - Incompatibilities + +% Package ulem: +% The package ulem has a lot of oddities. Using it is not always a +% good idea. If you really want to do so, you should import it with +% the [normalem] option, as such : +% \usepackage[normalem]{ulem} +% Otherwise, it overrides \emph to underline the emphasized text. So +% far so good, but underlined text is typesetted in a box, which means +% that linebreaks don't happen automatically. Since \abstract (among +% others) uses \emph, the abstract is unreadable by default. +% Please read thoroughly ulem's doc before using it. +% See also: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=underline + +%% +%% II - General LaTeX boilerplate +%% + +%% II.1 - Definition + +\NeedsTeXFormat{LaTeX2e}[1995/12/01] +\ProvidesClass{42-ro}[2010/07/15 v2.0 + LaTeX class for 42-ro-themed documents] + +%% II.2 - Class options and parent class + +\newcommand{\summarytitle}{Sumar}% + +\DeclareOption*{% + \PassOptionsToClass{\CurrentOption}{report} +} + +\ProcessOptions\relax +\LoadClass[a4paper,12pt,onecolumn]{report} + +%% II.3 - Imports + +\usepackage[top=1in,bottom=1in,left=1in,right=1in]{geometry} +\usepackage[pdftex]{graphicx} +\usepackage{url} +\usepackage{fancyhdr} +\usepackage{array} +\usepackage[table]{xcolor} +\usepackage[utf8x]{inputenc} +\usepackage[T1]{fontenc} +\usepackage{lmodern} +\usepackage{listings} +\usepackage{tabularx} +\usepackage{textcomp} +\usepackage{color} +\usepackage[pdftex]{hyperref} +\usepackage{fancybox} +\usepackage{float} +\usepackage{atbeginend} % provided locally : atbeginend.sty +\usepackage{tocloft} % provided locally : tocloft.sty +\usepackage{multirow} % provided locally : multirow.sty +\usepackage[romanian]{babel} + +%\usepackage{amsfonts} +\usepackage{minted} % provided locally : minted.sty +% Minted requires the Python "Pygments" librairy (http://pygments.org/). +% Pygments can be easily installed with the "easy_install" paquet manager +% from the "python-setuptools" paquet (sudo easy_install Pygments). +\usepackage{wallpaper} +%% III - Lengths and color redefinitions + +%% III.1 - Lengths + +\AfterBegin{enumerate}{ + \itemsep10pt% +} +\AfterBegin{itemize}{ + \itemsep10pt% + \renewcommand{\labelitemi}{$\bullet$}% + \renewcommand{\labelitemii}{$\circ$}% +} + +\BeforeBegin{enumerate}{\vspace{15pt}} +\AfterEnd{enumerate}{\vspace{15pt}} + +\BeforeBegin{itemize}{\vspace{15pt}} +\AfterEnd{itemize}{\vspace{15pt}} + +\BeforeBegin{lstlisting}{\vspace{15pt}} +\AfterEnd{lstlisting}{\vspace{15pt}} + +\BeforeBegin{tabularx}{\vspace{15pt}} +\AfterEnd{tabularx}{\vspace{15pt}} + +%% III.2 - Colors + +\definecolor{nicergreen}{rgb}{0,0.502,0} +\definecolor{nicerblue}{rgb}{0,0.302,1} +\definecolor{nicerorange}{rgb}{1,0.502,0} +\definecolor{nicergrey}{rgb}{0.502,0.502,0.502} +\definecolor{nicerred}{rgb}{0.626,0,0} +\definecolor{hintbg}{rgb}{1.0,1.0,0.75} +\definecolor{warnbg}{rgb}{1.0,0.75,0.75} +\definecolor{infobg}{rgb}{0.75,0.75,1.0} +\definecolor{bibliotechbg}{RGB}{239,253,255} +\definecolor{lightgrey}{rgb}{0.95,0.95,0.95} +\definecolor{darkgrey}{rgb}{0.1,0.1,0.1} +\definecolor{assholeblack}{rgb}{0,0,0} + +%% III.3 - Hyperlinks + +\hypersetup +{ + colorlinks, +% citecolor=black, % +% filecolor=black, % + linkcolor=black, % black links + urlcolor=blue % blue URLs +} + +%% III.4 - Listings + +\lstset +{ + backgroundcolor=\color{gray!15}, + basicstyle=\small\ttfamily, + breaklines=true, + columns=fullflexible, + frame=lines, + tabsize=4, + numbers=none, %numbers=left, + numberstyle=\scriptsize\ttfamily, + numbersep=5pt, + showspaces=false, + showstringspaces=false, + showtabs=false, + breaklines=true, + upquote=true, + float +} + +%% III.5 - Page layout + +\makeatletter +\pagestyle{fancy} +\lhead{\@title} +\rhead{\@subtitle} +\cfoot{\thepage} +\makeatother + +%% III.6 - Roman chapter style + +% custom sections style + +\renewcommand{\thechapter}{\Roman{chapter}} + +% Using roman numerals makes the TOC section/subsection numbers +% overflow on the right. This adds some margin to avoid that kind of +% problems. (requires \usepackage{tocloft}) +\setlength{\cftchapnumwidth}{1.5cm} +\setlength{\cftsecnumwidth}{1.5cm} +\setlength{\cftsubsecnumwidth}{1.3cm} +\setlength{\cftsubsubsecnumwidth}{1.6cm} +\setlength{\cftaftertoctitleskip}{0.5cm} + +%% IV - Frontpage customization + +%% IV.1 - Custom fields +\makeatletter +\newcommand{\website}[1]{\def \@website {#1}} +\website{} + +\newcommand{\subtitle}[1]{\def \@subtitle {#1}} +\subtitle{} + +\newcommand{\schoollogo}[1]{\def \@schoollogo {#1}} +\schoollogo{42_logo.pdf} + +\newcommand{\summary}[1]{\def \@summary {#1}} +\summary{} + +\edef\@authors{} +\newcommand{\member}[2]{% + \protected@edef\@authors{\@authors #1 \protect\url{#2}\\} + \author{\@authors} +} +\author{} + +%% IV.2 - Redefine \maketitle + +\makeatletter +\def \maketitle { + \begin{titlepage} + \begin{center} + %\begin{figure}[t] + \includegraphics[height=8cm]{\@schoollogo} + %\end{figure} + \vskip 5em + {\huge \@title} + \vskip 2em + {\LARGE \@subtitle} + \vskip 4em + \end{center} + \begin{center} + \@author + \end{center} + \vskip 5em + \begin{center} + \emph{\summarytitle : \@summary} + \end{center} + \end{titlepage} +} +\makeatother + +\TileWallPaper{\paperwidth}{\paperheight}{back} +%% IV.3 - Exercice number + +\newcounter{exerciceCounter} +\newcommand*{\exercicenumber}{ + \ifnum\value{exerciceCounter}<10 0\fi + \arabic{exerciceCounter} +} + +\newcommand*{\startexercices}{ + \setcounter{exerciceCounter}{0} +} + +\newcounter{itemizeCounter} +\setcounter{itemizeCounter}{0} +\BeforeBegin{itemize}{ + \addtocounter{itemizeCounter}{1} +} + +\AfterEnd{itemize}{ + \addtocounter{itemizeCounter}{-1} + \ifnum\value{itemizeCounter} = 0 + \stepcounter{exerciceCounter} + \fi +} + +%% V - Custom helper commands + +%% V.1 - Hint/Warn + +% hint command + +\newcommand{\kbox}[3] +{ + \vskip 15pt + \noindent + \colorbox{#1} + { + \begin{tabular*}{0.97\textwidth}{m{4em}m{0.8\textwidth}} + \includegraphics[width=4em]{#2} + & {\ttfamily\footnotesize #3}\\ + \end{tabular*} + } + \vskip 15pt +} + +\newcommand{\hint}[1]{\kbox{hintbg}{helphint.pdf}{#1}} +\newcommand{\warn}[1]{\kbox{warnbg}{warn.pdf}{#1}} +\newcommand{\info}[1]{\kbox{infobg}{info.pdf}{#1}} + +%% V.2 Lisibility helper + +\makeatletter +\newcommand{\mso}[1]{ + \ttfamily #1 \normalfont +} + +%% V.3 Exercise headers + +\makeatletter +\newcommand{\turnindir}[1]{\def \@turnindir {#1}} +\newcommand{\daypiscine}[1]{\def \@daypiscine {#1}} +\newcommand{\extitle}[1]{\def \@extitle {#1}} +\newcommand{\exnumber}[1]{\def \@exnumber {#1}} +\newcommand{\exscore}[1]{\def \@exscore {#1}} +\newcommand{\exflags}[1][-W -Wall -Werror]{\def \@exflags {#1}} +\newcommand{\excompil}[1][gcc]{\def \@excompil {#1}} +\newcommand{\exrules}[1][n/a]{\def \@exrules {#1}} +\newcommand{\exfiles}[1]{\def \@exfiles {#1}} +\newcommand{\exnotes}[1][n/a]{\def \@exnotes {#1}} +\newcommand{\exauthorize}[1]{\def \@exauthorize {#1}} +\newcommand{\exforbidden}[1]{\def \@exforbidden {#1}} +\newcommand{\exmake}[1][Nu]{\def \@exmake {#1}} + +% Default values +\turnindir{} +\daypiscine{} +\extitle{} +\exnumber{} +\exscore{} +\exflags{} +\excompil{} +\exrules{} +\exfiles{} +\exnotes{} +\exauthorize{Niciuna} +\exforbidden{Niciuna} +\exmake{} + +%Header pour exercices sans rien a "rendre" +\newcommand{\makeheaderbasic} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercictiu: \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Observatii: \ttfamily \@exnotes } + \\ \hline +\end{tabularx} +\exnotes +\exrules +\exmake +%\exauthorize +\exforbidden{Niciuna} +\extitle{} +\exnumber{} +} + +%Header pour exercices sans code mais fichiers a rendre +\newcommand{\makeheaderfilesforbidden} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercitiu: \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Director de lucru: \ttfamily + $ex\@exnumber/$ } + \\ \hline + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Fisier(e) de iesire: \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Functii interzise: \ttfamily \@exforbidden } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Observatii: \ttfamily \@exnotes } + \\ \hline +\end{tabularx} +\exnotes +\exrules +\exmake +\exauthorize{Niciuna} +\exforbidden{Niciuna} +\extitle{} +\exnumber{} +} + +%Header pour exercices sans code mais fichiers a rendre +\newcommand{\makeheaderfiles} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercitiu: \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Director de lucru: \ttfamily + $ex\@exnumber/$ } + \\ \hline + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Fisier(e) de iesire: \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Functii autorizate: \ttfamily \@exauthorize } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Observatii: \ttfamily \@exnotes } + \\ \hline +\end{tabularx} +\exnotes +\exrules +\exmake +\exauthorize{Niciuna} +\exforbidden +\extitle{} +\exnumber{} +} + +%Header pour exercices de code +\newcommand{\makeheadercode} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercitiu: \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} + %% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Director de lucru: \ttfamily + $ex\@exnumber/$ } + \\ \hline + + \multicolumn{2}{|>{\raggedright}m{7.5cm}} + {\small Compilator: \ttfamily \@excompil } & + \multicolumn{2}{|>{\raggedright}m{7.5cm}|} + {\small Flag-uri de compilare: + \ttfamily \@exflags } + \\ \hline + + \multicolumn{2}{|>{\raggedright}m{7.52cm}} + {\small Makefile: \ttfamily{\@exmake}} & + \multicolumn{2}{|>{\raggedright}m{7.5cm}|} + {Reguli : \ttfamily \@exrules } \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Fisiere de iesire: \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Observatii: \ttfamily \@exnotes } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Functii interzise: \ttfamily \@exforbidden } + \\ \hline +\end{tabularx} +\exnotes +\exrules +\exmake +\exforbidden{Niciuna} +\extitle{} +\exnumber{} +} + +\newcommand{\exmandatory}{Exercitiile obligatorii} +\newcommand{\exretrovalid}{Exercitiile retrovalidabile} +\newcommand{\exoptional}{Exercitiile bonus} + +\newcommand{\exercice}{Exercitiile} + +%% V.4 Reproduction from man +\newcommand{\reproductionfromman}[1]{Reproduceti identic comportamentul functiei \texttt{#1} (man #1).} + +%% VI - Syntactic highlights + + +%% Styles: +%% ~~~~~~~ +%% * monokai: +%% This style mimics the Monokai color scheme. +%% * manni: +%% A colorful style, inspired by the terminal highlighting style. +%% * rrt: +%% Minimalistic ``rrt'' theme, based on Zap and Emacs defaults. +%% * perldoc: +%% Style similar to the style used in the perldoc code blocks. +%% * borland: +%% Style similar to the style used in the borland IDEs. +%% * colorful: +%% A colorful style, inspired by CodeRay. +%% * default: +%% The default style (inspired by Emacs 22). +%% * murphy: +%% Murphy's style from CodeRay. +%% * vs: +%% +%% * trac: +%% Port of the default trac highlighter design. +%% * tango: +%% The Crunchy default Style inspired from the color palette from the Tango Icon Theme Guidelines. +%% * fruity: +%% Pygments version of the ``native'' vim theme. +%% * autumn: +%% A colorful style, inspired by the terminal highlighting style. +%% * bw: +%% +%% * emacs: +%% The default style (inspired by Emacs 22). +%% * vim: +%% Styles somewhat like vim 7.0 +%% * pastie: +%% Style similar to the pastie default style. +%% * friendly: +%% A modern style based on the VIM pyte theme. +%% * native: +%% Pygments version of the ``native'' vim theme. + + + +%\usemintedstyle{monokai} +%\usemintedstyle{manni} +%\usemintedstyle{rrt} +%\usemintedstyle{perldoc} +%\usemintedstyle{borland} +%\usemintedstyle{colorful} +%\usemintedstyle{default} +%\usemintedstyle{murphy} +%\usemintedstyle{vs} +%\usemintedstyle{trac} +%\usemintedstyle{tango} +%\usemintedstyle{fruity} +%\usemintedstyle{autumn} +%\usemintedstyle{bw} +%\usemintedstyle{emacs} +%\usemintedstyle{vim} +%\usemintedstyle{pastie} +%\usemintedstyle{friendly} +%\usemintedstyle{native} + +\makeatletter +\newenvironment{42ccode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{c} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + + +\makeatletter +\newenvironment{42ocamlcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{ocaml} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\definecolor{darcula-back}{RGB}{35, 37, 37} + +\makeatletter +\newenvironment{42javacode}{% + \VerbatimEnvironment + \usemintedstyle{monokai} + \minted@resetoptions + \definecolor{dark}{RGB}{35, 37, 37} + \setkeys{minted@opt}{bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{java} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42xmlcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=darcula-back,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{xml} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + + +\makeatletter +\newenvironment{42yamlcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{yaml} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + + +\lstnewenvironment{42console} { + \lstset { + basicstyle=\color{lightgrey}\scriptsize\ttfamily, + backgroundcolor=\color{assholeblack}, + breaklines=true, + numberstyle=\scriptsize, + columns=flexible, + keepspaces=true, + } +}{} diff --git a/resources/latex/42_logo.pdf b/resources/latex/42_logo.pdf new file mode 100644 index 00000000..1f5d3abb Binary files /dev/null and b/resources/latex/42_logo.pdf differ diff --git a/resources/latex/Makefile.LaTeX b/resources/latex/Makefile.LaTeX new file mode 100644 index 00000000..e80bfe9d --- /dev/null +++ b/resources/latex/Makefile.LaTeX @@ -0,0 +1,51 @@ +#******************************************************************************# +# # +# Makefile.LaTeX for LaTeX # +# Created on : Mon Oct 5 17:01:29 2015 # +# Make by : Uriel "Korfuri" Corfa # +# Made by : David "Thor" GIRON # +# # +#******************************************************************************# + +RESSOURCE_FILES = $(RELPATH)/Makefile.LaTeX \ + $(RELPATH)/atbeginend.sty \ + $(RELPATH)/tocloft.sty \ + $(RELPATH)/minted.sty \ + $(RELPATH)/multirow.sty \ + $(RELPATH)/42-fr.cls \ + $(RELPATH)/back.pdf \ + $(RELPATH)/42_logo.pdf \ + $(RELPATH)/info.pdf \ + $(RELPATH)/helphint.pdf \ + $(RELPATH)/warn.pdf + +ALL_DEPENDENCIES = $(RESSOURCE_FILES) $(DEPS) + +export TEXINPUTS := ..:.:$(RELPATH):${TEXINPUTS}: + +all: $(TARGETS) + +clean: + rm -f *.aux *.ent *.log *.out *.toc *.nav *.snm *.vrb *.pyg *.pdf.version *.fls *.fdb_latexmk + +distclean: clean + rm -f $(TARGETS) + +re: distclean all + +%.pdf: %.tex Makefile $(ALL_DEPENDENCIES) + pdflatex -shell-escape -halt-on-error $< + @if [ $$? = 0 ]; then\ + pdflatex -shell-escape -halt-on-error $<;\ + echo "Build OK";\ + else\ + echo "Build Failed";\ + exit 1;\ + fi + +view: all + (type xpdf > /dev/null 2>&1 && xpdf ${TARGETS}) ||\ + (type evince > /dev/null 2>&1 && evince ${TARGETS}) + + +#******************************************************************************# diff --git a/resources/latex/Makefile.template b/resources/latex/Makefile.template new file mode 100644 index 00000000..967b8739 --- /dev/null +++ b/resources/latex/Makefile.template @@ -0,0 +1,12 @@ +# List the pdf's to build. foo.tex will produce foo.pdf +TARGETS = foo.pdf + +# List the files included in the slides +DEPS = somePicture.png someSound.flac someOtherPicture.png + +# Relative path to the LaTeX documentclass setup files +# Adapt as needed +RELPATH = $(shell git rev-parse --show-toplevel)/templates/latex/ + +# You should not touch this either +include $(RELPATH)/Makefile.LaTeX diff --git a/resources/latex/atbeginend.sty b/resources/latex/atbeginend.sty new file mode 100644 index 00000000..f0d2878e --- /dev/null +++ b/resources/latex/atbeginend.sty @@ -0,0 +1,67 @@ +% atbeginend.sty +% +% From : http://www.eng.cam.ac.uk/help/tpl/textprocessing/atbeginend.sty +% +% defines +% \BeforeBegin{environment}{code-to-execute} +% \BeforeEnd {environment}{code-to-execute} +% \AfterBegin {environment}{code-to-execute} +% \AfterEnd {environment}{code-to-execute} +% +% Save \begin and \end to \BeginEnvironment and \EndEnvironment +\let\BeginEnvironment=\begin +\let\EndEnvironment=\end + +\def\IfUnDef#1{\expandafter\ifx\csname#1\endcsname\relax} + +% Null command needed to for \nothing{something}=.nothing. +\def\NullCom#1{} + +\def\begin#1{% +% +% if defined \BeforeBeg for this environment, execute it +\IfUnDef{BeforeBeg#1}\else\csname BeforeBeg#1\endcsname\fi% +% +% +% +\IfUnDef{AfterBeg#1}% This is done to skip the command for environments + % which can take arguments, like multicols; YOU MUST NOT + % USE \AfterBegin{...}{...} for such environments! + \let\SaveBegEng=\BeginEnvironment% +\else% + % Start this environment + \BeginEnvironment{#1}% + % and execute code after \begin{environment} + \csname AfterBeg#1\endcsname% + % + \let\SaveBegEng=\NullCom% +\fi% +\SaveBegEng{#1}% +} + + +\def\end#1{% +% +% execute code before \end{environment} +\IfUnDef{BeforeEnd#1}\else\csname BeforeEnd#1\endcsname\fi% +% +% close this environment +\EndEnvironment{#1}% +% +% and execute code after \begin{environment} +\IfUnDef{AfterEnd#1}\else\csname AfterEnd#1\endcsname\fi% +} + + +%% Now, define commands +% \BeforeBegin{environment}{code-to-execute} +% \BeforeEnd {environment}{code-to-execute} +% \AfterBegin {environment}{code-to-execute} +% \AfterEnd {environment}{code-to-execute} + +\def\BeforeBegin#1#2{\expandafter\gdef\csname BeforeBeg#1\endcsname +{#2}} +\def\BeforeEnd #1#2{\expandafter\gdef\csname BeforeEnd#1\endcsname +{#2}} +\def\AfterBegin #1#2{\expandafter\gdef\csname AfterBeg#1\endcsname {#2}} +\def\AfterEnd #1#2{\expandafter\gdef\csname AfterEnd#1\endcsname{#2}} diff --git a/resources/latex/back.pdf b/resources/latex/back.pdf new file mode 100644 index 00000000..fc4cfaff Binary files /dev/null and b/resources/latex/back.pdf differ diff --git a/resources/latex/dark-42-fr.cls b/resources/latex/dark-42-fr.cls new file mode 100644 index 00000000..c85154d7 --- /dev/null +++ b/resources/latex/dark-42-fr.cls @@ -0,0 +1,779 @@ +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% 42.cls +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% Authors: +% - Maxime "zaz" Montinet +% - David "Thor" Giron +% +% Contributors: +% - Mathieu Mahé +% - Gaëtan JUVIN +% - Unknown for now +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +% This class provides a layout for teaching material at 42. +% +% This class is organized this way : +% +% I - Documentation +% 1. Incompatibilites +% II - General LaTeX boilerplate +% 1. Definition +% 2. Class options and parent class +% 3. Imports +% III - Lengths and color redefinitions +% 1. Lenghts +% 2. Colors +% 3. Hyperlinks +% 4. Listings +% 5. Page layout +% 6. Roman numerals for chapters +% IV - Frontpage customization +% 1. Custom fields +% 2. Redefinition of \maketitle +% 3. Exercice number +% V - Custom helper commands +% 1. Hint/warn +% 2. Lisibility helper +% 3. Exercise headers +% 4. Reproduction from man + +%% +%% I - Documentation +%% + +%% I.1 - Incompatibilities + +% Package ulem: +% The package ulem has a lot of oddities. Using it is not always a +% good idea. If you really want to do so, you should import it with +% the [normalem] option, as such : +% \usepackage[normalem]{ulem} +% Otherwise, it overrides \emph to underline the emphasized text. So +% far so good, but underlined text is typesetted in a box, which means +% that linebreaks don't happen automatically. Since \abstract (among +% others) uses \emph, the abstract is unreadable by default. +% Please read thoroughly ulem's doc before using it. +% See also: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=underline + +%% +%% II - General LaTeX boilerplate +%% + +%% II.1 - Definition + +\NeedsTeXFormat{LaTeX2e}[1995/12/01] +\ProvidesClass{42}[2016/11/11 v1.0 + LaTeX class for 42-themed documents - Dark flavored] + +%% II.2 - Class options and parent class + +\newcommand{\summarytitle}{R\'esum\'e}% + +\DeclareOption*{% + \PassOptionsToClass{\CurrentOption}{report} +} + +\ProcessOptions\relax +\LoadClass[a4paper,12pt,onecolumn]{report} + +%% II.3 - Imports + +\usepackage[top=1in,bottom=1in,left=1in,right=1in]{geometry} +\usepackage[pdftex]{graphicx} +\usepackage{url} +\usepackage{fancyhdr} +\usepackage{array} +\usepackage[table]{xcolor} +\usepackage[utf8]{inputenc} +\usepackage[T1]{fontenc} +\usepackage{lmodern} +\usepackage{listings} +\usepackage{tabularx} +\usepackage{textcomp} +\usepackage{color} +\usepackage[pdftex]{hyperref} +\usepackage{fancybox} +\usepackage{float} +\usepackage{atbeginend} % provided locally : atbeginend.sty +\usepackage{tocloft} % provided locally : tocloft.sty +\usepackage{multirow} % provided locally : multirow.sty +\usepackage[french]{babel} +\usepackage{minted} % provided locally : minted.sty +% Minted requires the Python "Pygments" librairy (http://pygments.org/). +% Pygments can be easily installed with the "easy_install" paquet manager +% from the "python-setuptools" paquet (sudo easy_install Pygments). +\usepackage{pifont,mdframed} +%% III - Lengths and color redefinitions +%% III.1 - Lengths + +\AfterBegin{enumerate}{ + \itemsep10pt% +} +\AfterBegin{itemize}{ + \itemsep10pt% + \renewcommand{\labelitemi}{$\bullet$}% + \renewcommand{\labelitemii}{$\circ$}% +} + +\BeforeBegin{enumerate}{\vspace{15pt}} +\AfterEnd{enumerate}{\vspace{15pt}} + +\BeforeBegin{itemize}{\vspace{15pt}} +\AfterEnd{itemize}{\vspace{15pt}} + +\BeforeBegin{lstlisting}{\vspace{15pt}} +\AfterEnd{lstlisting}{\vspace{15pt}} + +\BeforeBegin{tabularx}{\vspace{15pt}} +\AfterEnd{tabularx}{\vspace{15pt}} + +%% III.2 - Colors + +\definecolor{nicergreen}{rgb}{0,0.502,0} +\definecolor{nicerblue}{rgb}{0,0.302,1} +\definecolor{nicerorange}{rgb}{1,0.502,0} +\definecolor{nicergrey}{rgb}{0.502,0.502,0.502} +\definecolor{nicerred}{rgb}{0.626,0,0} +\definecolor{hintbg}{rgb}{1.0,1.0,0.75} +\definecolor{warnbg}{rgb}{1.0,0.75,0.75} +\definecolor{infobg}{rgb}{0.75,0.75,1.0} +\definecolor{bibliotechbg}{RGB}{239,253,255} +\definecolor{lightgrey}{rgb}{0.95,0.95,0.95} +\definecolor{darkgrey}{rgb}{0.1,0.1,0.1} +\definecolor{assholeblack}{rgb}{0,0,0} + +%% III.3 - Hyperlinks + + +\color{lightgrey} + + +\hypersetup +{ + colorlinks, +% citecolor=black, % +% filecolor=black, % + linkcolor=black, % black links + urlcolor=blue % blue URLs +} + +%% III.4 - Listings + +\lstset +{ + backgroundcolor=\color{gray!15}, + basicstyle=\small\ttfamily, + breaklines=true, + columns=fullflexible, + frame=lines, + tabsize=4, + numbers=none, %numbers=left, + numberstyle=\scriptsize\ttfamily, + numbersep=5pt, + showspaces=false, + showstringspaces=false, + showtabs=false, + breaklines=true, + upquote=true, + float +} + +%% III.5 - Page layout + +\makeatletter +\pagestyle{fancy} +\lhead{\@title} +\rhead{\@subtitle} +\cfoot{\thepage} +\makeatother + +%% III.6 - Roman chapter style + +% custom sections style + +\renewcommand{\thechapter}{\Roman{chapter}} + +% Using roman numerals makes the TOC section/subsection numbers +% overflow on the right. This adds some margin to avoid that kind of +% problems. (requires \usepackage{tocloft}) +\setlength{\cftchapnumwidth}{1.5cm} +\setlength{\cftsecnumwidth}{1.5cm} +\setlength{\cftsubsecnumwidth}{1.3cm} +\setlength{\cftsubsubsecnumwidth}{1.6cm} +\setlength{\cftaftertoctitleskip}{0.5cm} + +%% IV - Frontpage customization + +%% IV.1 - Custom fields +\makeatletter +\newcommand{\website}[1]{\def \@website {#1}} +\website{} + +\newcommand{\subtitle}[1]{\def \@subtitle {#1}} +\subtitle{} + +\newcommand{\schoollogo}[1]{\def \@schoollogo {#1}} +\schoollogo{dark-42_logo.pdf} + +\newcommand{\summary}[1]{\def \@summary {#1}} +\summary{} + +\edef\@authors{} +\newcommand{\member}[2]{% + \protected@edef\@authors{\@authors #1 \protect\url{#2}\\} + \author{\@authors} +} +\author{} + +\renewcommand{\cftchapfont}{\color{lightgrey}} +\renewcommand{\cftsecfont}{\color{lightgrey}} +\renewcommand{\cftsubsecfont}{\color{lightgrey}} + +%% IV.2 - Redefine \maketitle + +\makeatletter +\def \maketitle { + \begin{titlepage} + \begin{center} + %\begin{figure}[t] + \includegraphics[height=8cm]{\@schoollogo} + %\end{figure} + \vskip 5em + {\huge \@title} + \vskip 2em + {\LARGE \@subtitle} + \vskip 4em + \end{center} + \begin{center} + \@author + \end{center} + \vskip 5em + \begin{center} + \emph{\summarytitle : \@summary} + \end{center} + \end{titlepage} +} +\makeatother + +\fancyput(-2.54cm,-27.16cm){\includegraphics[width=21cm,height=29.7cm]{dark-back}} + +%% IV.3 - Exercice number + +\newcounter{exerciceCounter} +\newcommand*{\exercicenumber}{ + \ifnum\value{exerciceCounter}<10 0\fi + \arabic{exerciceCounter} +} + +\newcommand*{\startexercices}{ + \setcounter{exerciceCounter}{0} +} + +\newcommand*{\nextexercice}{ + \stepcounter{exerciceCounter} +} + +\newcounter{itemizeCounter} +\setcounter{itemizeCounter}{0} +\BeforeBegin{itemize}{ + \addtocounter{itemizeCounter}{1} +} + +\AfterEnd{itemize}{ + \addtocounter{itemizeCounter}{-1} + \ifnum\value{itemizeCounter} = 0 + \stepcounter{exerciceCounter} + \fi +} + +%% V - Custom helper commands + +%% V.1 - Hint/Warn + +% hint command + +\newcommand{\kbox}[3] +{ + \vskip 15pt + \noindent + \colorbox{#1} + { + \begin{tabular*}{0.97\textwidth}{m{4em}m{0.8\textwidth}} + \includegraphics[width=4em]{#2} + & {\ttfamily\footnotesize #3}\\ + \end{tabular*} + } + \vskip 15pt +} + +\newcommand{\hint}[1]{\kbox{hintbg}{helphint.pdf}{\color{assholeblack} #1}} +\newcommand{\warn}[1]{\kbox{warnbg}{warn.pdf}{\color{assholeblack} #1}} +\newcommand{\info}[1]{\kbox{infobg}{info.pdf}{\color{assholeblack} #1}} + +%% V.2 Lisibility helper + +\makeatletter +\newcommand{\mso}[1]{ + \ttfamily #1 \normalfont +} + +%% V.3 Exercise headers + +\makeatletter +\newcommand{\turnindir}[1]{\def \@turnindir {#1}} +\newcommand{\daypiscine}[1]{\def \@daypiscine {#1}} +\newcommand{\extitle}[1]{\def \@extitle {#1}} +\newcommand{\exnumber}[1]{\def \@exnumber {#1}} +\newcommand{\exscore}[1]{\def \@exscore {#1}} +\newcommand{\exflags}[1][-W -Wall -Werror]{\def \@exflags {#1}} +\newcommand{\excompil}[1][gcc]{\def \@excompil {#1}} +\newcommand{\exrules}[1][n/a]{\def \@exrules {#1}} +\newcommand{\exfiles}[1]{\def \@exfiles {#1}} +\newcommand{\exnotes}[1][n/a]{\def \@exnotes {#1}} +\newcommand{\exauthorize}[1]{\def \@exauthorize {#1}} +\newcommand{\exforbidden}[1]{\def \@exforbidden {#1}} +\newcommand{\exmake}[1][Non]{\def \@exmake {#1}} + +% Default values +\turnindir{} +\daypiscine{} +\extitle{} +\exnumber{} +\exscore{} +\exflags{} +\excompil{} +\exrules{} +\exfiles{} +\exnotes{} +\exauthorize{Aucune} +\exforbidden{Aucune} +\exmake{} + +%Header pour exercices sans rien a "rendre" +\newcommand{\makeheaderbasic} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercice : \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Remarques : \ttfamily \@exnotes } + \\ \hline +\end{tabularx} +\exnotes +\exrules +\exmake +%\exauthorize +\exforbidden{Aucune} +\extitle{} +\exnumber{} +} + +%Header pour exercices sans code mais fichiers a rendre +\newcommand{\makeheaderfiles} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercice : \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Dossier de rendu : \ttfamily + $ex\@exnumber/$ } + \\ \hline + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Fichiers \`a rendre : \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Fonctions Autoris\'ees : \ttfamily \@exauthorize } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Remarques : \ttfamily \@exnotes } + \\ \hline +\end{tabularx} +\exnotes +\exrules +\exmake +\exauthorize{Aucune} +\exforbidden{Aucune} +\extitle{} +\exnumber{} +} + +%Header pour exercices sans dossier de rendu +\newcommand{\makeheaderfilesnodirectory} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercice : \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Fichiers \`a rendre : \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Fonctions Autoris\'ees : \ttfamily \@exauthorize } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Remarques : \ttfamily \@exnotes } + \\ \hline +\end{tabularx} +\exnotes +\exrules +\exmake +\exauthorize{Aucune} +\exforbidden{Aucune} +\extitle{} +\exnumber{} +} + +%Header pour exercices sans code mais fichiers a rendre +\newcommand{\makeheaderfilesforbidden} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercice : \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} +%% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Dossier de rendu : \ttfamily + $ex\@exnumber/$ } + \\ \hline + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Fichiers \`a rendre : \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Fonctions interdites : \ttfamily \@exforbidden } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Remarques : \ttfamily \@exnotes } + \\ \hline +\end{tabularx} +\exnotes +\exrules +\exmake +\exauthorize{Aucune} +\exforbidden{Aucune} +\extitle{} +\exnumber{} +} + +%Header pour exercices de code +\newcommand{\makeheadercode} +{ + \noindent + \begin{tabularx}{\textwidth}{|X X X X|} + \hline + \multicolumn{1}{|>{\raggedright}m{1cm}|} + {\vskip 2mm \includegraphics[height=1cm]{\@schoollogo}} & + \multicolumn{2}{>{\centering}m{12cm}}{\small Exercice : \@exnumber } & + \multicolumn{1}{ >{\raggedleft}p{1.5cm}|} + %% {\scriptsize points : \@exscore} \\ \hline + {} \\ \hline + + \multicolumn{4}{|>{\centering}m{15cm}|} + {\small \@extitle} \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Dossier de rendu: \ttfamily + $ex\@exnumber/$ } + \\ \hline + + \multicolumn{2}{|>{\raggedright}m{7.5cm}} + {\small Compilateur : \ttfamily \@excompil } & + \multicolumn{2}{|>{\raggedright}m{7.5cm}|} + {\small Flags de compilation: + \ttfamily \@exflags } + \\ \hline + + \multicolumn{2}{|>{\raggedright}m{7.52cm}} + {\small Makefile : \ttfamily{\@exmake}} & + \multicolumn{2}{|>{\raggedright}m{7.5cm}|} + {R\`{e}gles : \ttfamily \@exrules } \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Fichiers \`a rendre : \ttfamily \@exfiles } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Remarques : \ttfamily \@exnotes } + \\ \hline + + \multicolumn{4}{|>{\raggedright}m{15cm}|} + {\small Fonctions Interdites : \ttfamily \@exforbidden } + \\ \hline +\end{tabularx} +\exnotes +\exrules +\exmake +\exforbidden{Aucune} +\extitle{} +\exnumber{} +} + +\newcommand{\exmandatory}{Exercice obligatoire} +\newcommand{\exretrovalid}{Exercice rétrovalidable} +\newcommand{\exoptional}{Exercice bonus} + +\newcommand{\exercice}{Exercice} + +%% V.4 Reproduction from man +\newcommand{\reproductionfromman}[1]{Reproduire \`a l'identique le fonctionnement de la fonction \texttt{#1} (man #1).} + +%% VI - Syntactic highlights + + +%% Styles: +%% ~~~~~~~ +%% * monokai: +%% This style mimics the Monokai color scheme. +%% * manni: +%% A colorful style, inspired by the terminal highlighting style. +%% * rrt: +%% Minimalistic ``rrt'' theme, based on Zap and Emacs defaults. +%% * perldoc: +%% Style similar to the style used in the perldoc code blocks. +%% * borland: +%% Style similar to the style used in the borland IDEs. +%% * colorful: +%% A colorful style, inspired by CodeRay. +%% * default: +%% The default style (inspired by Emacs 22). +%% * murphy: +%% Murphy's style from CodeRay. +%% * vs: +%% +%% * trac: +%% Port of the default trac highlighter design. +%% * tango: +%% The Crunchy default Style inspired from the color palette from the Tango Icon Theme Guidelines. +%% * fruity: +%% Pygments version of the ``native'' vim theme. +%% * autumn: +%% A colorful style, inspired by the terminal highlighting style. +%% * bw: +%% +%% * emacs: +%% The default style (inspired by Emacs 22). +%% * vim: +%% Styles somewhat like vim 7.0 +%% * pastie: +%% Style similar to the pastie default style. +%% * friendly: +%% A modern style based on the VIM pyte theme. +%% * native: +%% Pygments version of the ``native'' vim theme. + + + +%\usemintedstyle{monokai} +%\usemintedstyle{manni} +%\usemintedstyle{rrt} +%\usemintedstyle{perldoc} +%\usemintedstyle{borland} +%\usemintedstyle{colorful} +%\usemintedstyle{default} +%\usemintedstyle{murphy} +%\usemintedstyle{vs} +%\usemintedstyle{trac} +%\usemintedstyle{tango} +%\usemintedstyle{fruity} +%\usemintedstyle{autumn} +%\usemintedstyle{bw} +%\usemintedstyle{emacs} +%\usemintedstyle{vim} +%\usemintedstyle{pastie} +%\usemintedstyle{friendly} +%\usemintedstyle{native} + +\makeatletter +\newenvironment{42ccode}{% + \VerbatimEnvironment + \usemintedstyle{emacs} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{c} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42phpcode}{% + \VerbatimEnvironment + \usemintedstyle{emacs} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{html+php} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42jscode}{% + \VerbatimEnvironment + \usemintedstyle{emacs} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{%[ + \end{VerbatimOut} + \minted@pygmentize{js} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42yamlcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{yaml} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\makeatletter +\newenvironment{42cppcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{c++} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + + +\makeatletter +\newenvironment{42ocamlcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{ocaml} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + + +\makeatletter +\newenvironment{42asmcode}{% + \VerbatimEnvironment + \usemintedstyle{native} + \minted@resetoptions + \setkeys{minted@opt}{bgcolor=black,formatcom=\color{lightgrey},fontsize=\scriptsize} + \begin{figure}[ht!] + \centering + \begin{minipage}{16cm} + \begin{VerbatimOut}{\jobname.pyg}} +{% + \end{VerbatimOut} + \minted@pygmentize{nasm} + \DeleteFile{\jobname.pyg} + \end{minipage} +\end{figure}} +\makeatother + +\lstnewenvironment{42console} { + \lstset { + extendedchars=true, + literate={✓}{{\checkmark}}1, + basicstyle=\color{lightgrey}\scriptsize\ttfamily, + backgroundcolor=\color{assholeblack}, + breaklines=true, + numberstyle=\scriptsize, + columns=flexible, + keepspaces=true, + } +}{} + +\newenvironment{42warning} + { + \color{assholeblack} + \vspace*{1\baselineskip} + \par\begin{mdframed}[linewidth=2pt,linecolor=red]% + \begin{list}{}{\leftmargin=1cm + \labelwidth=\leftmargin}\item[\Large\ding{43}]} + {\end{list}\end{mdframed}\par \vspace*{1\baselineskip}} diff --git a/resources/latex/dark-42_logo.pdf b/resources/latex/dark-42_logo.pdf new file mode 100644 index 00000000..2876a6b9 Binary files /dev/null and b/resources/latex/dark-42_logo.pdf differ diff --git a/resources/latex/dark-back.pdf b/resources/latex/dark-back.pdf new file mode 100644 index 00000000..0c854f2e Binary files /dev/null and b/resources/latex/dark-back.pdf differ diff --git a/resources/latex/helphint.pdf b/resources/latex/helphint.pdf new file mode 100644 index 00000000..08e79a51 Binary files /dev/null and b/resources/latex/helphint.pdf differ diff --git a/resources/latex/info.pdf b/resources/latex/info.pdf new file mode 100644 index 00000000..36c6eaf7 Binary files /dev/null and b/resources/latex/info.pdf differ diff --git a/resources/latex/minted.sty b/resources/latex/minted.sty new file mode 100644 index 00000000..0e0585cf --- /dev/null +++ b/resources/latex/minted.sty @@ -0,0 +1,239 @@ +%% +%% This is file `minted.sty', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% minted.dtx (with options: `package') +%% Copyright 2010--2011 Konrad Rudolph +%% +%% This work may be distributed and/or modified under the +%% conditions of the LaTeX Project Public License, either version 1.3 +%% of this license or (at your option) any later version. +%% The latest version of this license is in +%% http://www.latex-project.org/lppl.txt +%% and version 1.3 or later is part of all distributions of LaTeX +%% version 2005/12/01 or later. +%% +%% Additionally, the project may be distributed under the terms of the new BSD +%% license. +%% +%% This work has the LPPL maintenance status `maintained'. +%% +%% The Current Maintainer of this work is Konrad Rudolph. +%% +%% This work consists of the files minted.dtx and minted.ins +%% and the derived file minted.sty. +\NeedsTeXFormat{LaTeX2e} +\ProvidesPackage{minted}[2011/09/17 v1.7 Yet another Pygments shim for LaTeX] +\RequirePackage{keyval} +\RequirePackage{fancyvrb} +\RequirePackage{xcolor} +\RequirePackage{float} +\RequirePackage{ifthen} +\RequirePackage{calc} +\RequirePackage{ifplatform} +\DeclareOption{chapter}{\def\minted@float@within{chapter}} +\DeclareOption{section}{\def\minted@float@within{section}} +\ProcessOptions\relax +\ifwindows + \providecommand\DeleteFile[1]{\immediate\write18{del #1}} +\else + \providecommand\DeleteFile[1]{\immediate\write18{rm #1}} +\fi +\newboolean{AppExists} +\newcommand\TestAppExists[1]{ + \ifwindows + \DeleteFile{\jobname.aex} + \immediate\write18{for \string^\@percentchar i in (#1.exe #1.bat #1.cmd) + do set >\jobname.aex >\jobname.aex} %$ + \newread\@appexistsfile + \immediate\openin\@appexistsfile\jobname.aex + \expandafter\def\expandafter\@tmp@cr\expandafter{\the\endlinechar} + \endlinechar=-1\relax + \readline\@appexistsfile to \@apppathifexists + \endlinechar=\@tmp@cr + \ifthenelse{\equal{\@apppathifexists}{}} + {\AppExistsfalse} + {\AppExiststrue} + \immediate\closein\@appexistsfile + \DeleteFile{\jobname.aex} +\immediate\typeout{file deleted} + \else + \immediate\write18{which #1 && touch \jobname.aex} + \IfFileExists{\jobname.aex} + {\AppExiststrue + \DeleteFile{\jobname.aex}} + {\AppExistsfalse} + \fi} +\newcommand\minted@resetoptions{} +\newcommand\minted@defopt[1]{ + \expandafter\def\expandafter\minted@resetoptions\expandafter{% + \minted@resetoptions + \@namedef{minted@opt@#1}{}}} +\newcommand\minted@opt[1]{ + \expandafter\detokenize% + \expandafter\expandafter\expandafter{\csname minted@opt@#1\endcsname}} +\newcommand\minted@define@opt[3][]{ + \minted@defopt{#2} + \ifthenelse{\equal{#1}{}}{ + \define@key{minted@opt}{#2}{\@namedef{minted@opt@#2}{#3}}} + {\define@key{minted@opt}{#2}[#1]{\@namedef{minted@opt@#2}{#3}}}} +\newcommand\minted@define@switch[3][]{ + \minted@defopt{#2} + \define@booleankey{minted@opt}{#2} + {\@namedef{minted@opt@#2}{#3}} + {\@namedef{minted@opt@#2}{#1}}} +\minted@defopt{extra} +\newcommand\minted@define@extra[1]{ + \define@key{minted@opt}{#1}{ + \expandafter\def\expandafter\minted@opt@extra\expandafter{% + \minted@opt@extra,#1=##1}}} +\newcommand\minted@define@extra@switch[1]{ + \define@booleankey{minted@opt}{#1} + {\expandafter\def\expandafter\minted@opt@extra\expandafter{% + \minted@opt@extra,#1}} + {\expandafter\def\expandafter\minted@opt@extra\expandafter{% + \minted@opt@extra,#1=false}}} +\minted@define@switch{texcl}{-P texcomments} +\minted@define@switch{mathescape}{-P mathescape} +\minted@define@switch{linenos}{-P linenos} +\minted@define@switch{startinline}{-P startinline} +\minted@define@switch[-P funcnamehighlighting=False]% + {funcnamehighlighting}{-P funcnamehighlighting} +\minted@define@opt{gobble}{-F gobble:n=#1} +\minted@define@opt{bgcolor}{#1} +\minted@define@extra{frame} +\minted@define@extra{framesep} +\minted@define@extra{framerule} +\minted@define@extra{rulecolor} +\minted@define@extra{numbersep} +\minted@define@extra{firstnumber} +\minted@define@extra{stepnumber} +\minted@define@extra{firstline} +\minted@define@extra{lastline} +\minted@define@extra{baselinestretch} +\minted@define@extra{xleftmargin} +\minted@define@extra{xrightmargin} +\minted@define@extra{fillcolor} +\minted@define@extra{tabsize} +\minted@define@extra{fontfamily} +\minted@define@extra{fontsize} +\minted@define@extra{fontshape} +\minted@define@extra{fontseries} +\minted@define@extra{formatcom} +\minted@define@extra{label} +\minted@define@extra@switch{numberblanklines} +\minted@define@extra@switch{showspaces} +\minted@define@extra@switch{resetmargins} +\minted@define@extra@switch{samepage} +\minted@define@extra@switch{showtabs} +\minted@define@extra@switch{obeytabs} +\newsavebox{\minted@bgbox} +\newenvironment{minted@colorbg}[1]{ + \def\minted@bgcol{#1} + \noindent + \begin{lrbox}{\minted@bgbox} + \begin{minipage}{\linewidth-2\fboxsep}} + {\end{minipage} + \end{lrbox}% + \colorbox{\minted@bgcol}{\usebox{\minted@bgbox}}} +\newwrite\minted@code +\newcommand\minted@savecode[1]{ + \immediate\openout\minted@code\jobname.pyg + \immediate\write\minted@code{#1} + \immediate\closeout\minted@code} +\newcommand\minted@pygmentize[2][\jobname.pyg]{ + \def\minted@cmd{pygmentize -l #2 -f latex -F tokenmerge + \minted@opt{gobble} \minted@opt{texcl} \minted@opt{mathescape} + \minted@opt{startinline} \minted@opt{funcnamehighlighting} + \minted@opt{linenos} -P "verboptions=\minted@opt{extra}" + -o \jobname.out.pyg #1} + \immediate\write18{\minted@cmd} + % For debugging, uncomment: + %\immediate\typeout{\minted@cmd} + \ifthenelse{\equal{\minted@opt@bgcolor}{}} + {} + {\begin{minted@colorbg}{\minted@opt@bgcolor}} + \input{\jobname.out.pyg} + \ifthenelse{\equal{\minted@opt@bgcolor}{}} + {} + {\end{minted@colorbg}} + \DeleteFile{\jobname.out.pyg}} +\newcommand\minted@usedefaultstyle{\usemintedstyle{default}} +\newcommand\usemintedstyle[1]{ + \renewcommand\minted@usedefaultstyle{} + \immediate\write18{pygmentize -S #1 -f latex > \jobname.pyg} + \input{\jobname.pyg}} +\newcommand\mint[3][]{ + \DefineShortVerb{#3} + \minted@resetoptions + \setkeys{minted@opt}{#1} + \SaveVerb[aftersave={ + \UndefineShortVerb{#3} + \minted@savecode{\FV@SV@minted@verb} + \minted@pygmentize{#2} + \DeleteFile{\jobname.pyg}}]{minted@verb}#3} +\newcommand\minted@proglang[1]{} +\newenvironment{minted}[2][] + {\VerbatimEnvironment + \renewcommand{\minted@proglang}[1]{#2} + \minted@resetoptions + \setkeys{minted@opt}{#1} + \begin{VerbatimOut}[codes={\catcode`\^^I=12}]{\jobname.pyg}}% + {\end{VerbatimOut} + \minted@pygmentize{\minted@proglang{}} + \DeleteFile{\jobname.pyg}} +\newcommand\inputminted[3][]{ + \minted@resetoptions + \setkeys{minted@opt}{#1} + \minted@pygmentize[#3]{#2}} +\newcommand\newminted[3][]{ + \ifthenelse{\equal{#1}{}} + {\def\minted@envname{#2code}} + {\def\minted@envname{#1}} + \newenvironment{\minted@envname} + {\VerbatimEnvironment\begin{minted}[#3]{#2}} + {\end{minted}} + \newenvironment{\minted@envname *}[1] + {\VerbatimEnvironment\begin{minted}[#3,##1]{#2}} + {\end{minted}}} +\newcommand\newmint[3][]{ + \ifthenelse{\equal{#1}{}} + {\def\minted@shortname{#2}} + {\def\minted@shortname{#1}} + \expandafter\newcommand\csname\minted@shortname\endcsname[2][]{ + \mint[#3,##1]{#2}##2}} +\newcommand\newmintedfile[3][]{ + \ifthenelse{\equal{#1}{}} + {\def\minted@shortname{#2file}} + {\def\minted@shortname{#1}} + \expandafter\newcommand\csname\minted@shortname\endcsname[2][]{ + \inputminted[#3,##1]{#2}{##2}}} +\@ifundefined{minted@float@within} + {\newfloat{listing}{h}{lol}} + {\newfloat{listing}{h}{lol}[\minted@float@within]} +\newcommand\listingscaption{Listing} +\floatname{listing}{\listingscaption} +\newcommand\listoflistingscaption{List of listings} +\providecommand\listoflistings{\listof{listing}{\listoflistingscaption}} +\AtBeginDocument{ + \minted@usedefaultstyle} +\AtEndOfPackage{ + \ifnum\pdf@shellescape=1\relax\else + \PackageError{minted} + {You must invoke LaTeX with the + -shell-escape flag} + {Pass the -shell-escape flag to LaTeX. Refer to the minted.sty + documentation for more information.}\fi + \TestAppExists{pygmentize} + \ifAppExists\else + \PackageError{minted} + {You must have `pygmentize' installed + to use this package} + {Refer to the installation instructions in the minted + documentation for more information.} + \fi} +\endinput +%% +%% End of file `minted.sty'. diff --git a/resources/latex/multirow.sty b/resources/latex/multirow.sty new file mode 100644 index 00000000..f52132fd --- /dev/null +++ b/resources/latex/multirow.sty @@ -0,0 +1,159 @@ +%% +%% multirow.sty V1.6 version (5-May-2004) +%% +%% Author: Jerry Leichter +%% Piet van Oostrum +%% +%% This file may be distributed under the terms of the LaTeX Project Public +%% License, as described in lppl.txt in the base LaTeX distribution. +%% Either version 1 or, at your option, any later version. +%% +%% V1.0 was distributed anonymously, based on a Usenet posting that was +%% not intended for stand-alone use. +%% V1.1 was modified by Piet van Oostrum to allow it to +%% work without bigstrut.sty. +%% V1.2 was modified by Jerry Leichter for the same goal, but using a +%% different approach which will work properly in conjunction with +%% bigstrut.sty. +%% V1.2a was modified by Piet van Oostrum to use \vskip +%% instead of \raise in positioning, avoiding making rows too high +%% when the adjustment is large. +%% V1.3 was modified by Piet van Oostrum to work properly in a p{} column +%% (\leavevmode added) +%% V1.4 was modified by Piet van Oostrum to check for the special case that +%% the width is given as an *. In this case the natural +%% width of the text argument will be used and the argument +%% is processed in LR-mode. +%% V1.5 was modified by Piet van Oostrum: Added a % after \hbox{#5}\vfill}. +%% Added \struts around #5 for better vertical positioning. +%% Additional coding for negative value of nrows. +%% V1.6 was modified by Piet van Oostrum: Replace a space by \relax after +%% \advance\@tempdima#4. +%% +% Make an entry that will span multiple rows of a table. +% +% \multirow{nrows}[bigstruts]{width}[fixup]{text} +% +% nrows is the number of rows to span. It's up to you to leave the other +% rows empty, or the stuff created by \multirow will over-write it. +% With a positive value of nrows the spanned colomns are this row and +% (nrows-1) rows below it. With a negative value of nrows they are +% this row and (1-nrows) above it. +% +% bigstruts is mainly used if you've used bigstrut.sty. In that case it +% is the total number of uses of \bigstrut within the rows being +% spanned. Count 2 uses for each \bigstrut, 1 for each \bigstrut[x] +% where x is either t or b. The default is 0. +% width is the width to which the text is to be set, or * to indicate that +% the text argument's natural width is to be used. +% +% text is the actual text. If the width was set explicitly, the text will +% be set in a parbox of that width; you can use \\ to force linebreaks +% where you like. +% +% If the width was given as * the text will be set in LR mode. If you +% want a multiline entry in this case you should use a tabular or array +% in the text parameter. +% +% The text is centered vertically within the range spanned by nrows. +% +% fixup is a length used for fine tuning: The text will be raised (or +% lowered, if fixup is negative) by that length above (below) wherever +% it would otherwise have gone. +% +% For example (using both multirow and bigstrut) +% +% \newcommand{\minitab}[2][l]{\begin{tabular}{#1}#2\end{tabular}} +% \begin{tabular}{|c|c|} +% \hline +% \multirow{4}{1in}{Common g text} & Column g2a\\ +% & Column g2b \\ +% & Column g2c \\ +% & Column g2d \\ +% \hline +% \multirow{3}[6]*{Common g text} & Column g2a\bigstrut\\\cline{2-2} +% & Column g2b \bigstrut\\\cline{2-2} +% & Column g2c \bigstrut\\ +% \hline +% \multirow{4}[8]{1in}{Common g text} & Column g2a\bigstrut\\\cline{2-2} +% & Column g2b \bigstrut\\\cline{2-2} +% & Column g2c \bigstrut\\\cline{2-2} +% & Column g2d \bigstrut\\ +% \hline +% \multirow{4}*{\minitab[c]{Common \\ g text}} & Column g2a\\ +% & Column g2b \\ +% & Column g2c \\ +% & Column g2d \\ +% \hline +% \end{tabular} +% +% If any of the spanned rows are unusually large, or if you're using +% bigstrut.sty and \bigstrut's are used assymetrically about the centerline of +% the spanned rows, the vertical centering may not come out right. Use the +% fixup argument in this case. +% +% Just before "text" is expanded, the \multirowsetup macro is expanded to +% set up any special environment. Initially, \multirowsetup contains just +% \raggedright. It can be redefined with \renewcommand. +% +% Bugs: It's just about impossible to deal correctly with descenders. The +% text will be set up centered, but it may then have a baseline that doesn't +% match the baseline of the stuff beside it, in particular if the stuff +% beside it has descenders and "text" does not. This may result in a small +% missalignment. About all that can be done is to do a final touchup on +% "text", using the fixup optional argument. (Hint: If you use a measure +% like .1ex, there's a reasonable chance that the fixup will still be correct +% if you change the point size.) +% +% \multirow is mainly designed for use with table, as opposed to array, +% environments. It will not work well in an array environment since the lines +% have an extra \jot of space between them which it won't account for. Fixing +% this is difficult in general, and doesn't seem worth it. The bigstruts +% argument can be used to provide a semi-automatic fix: First set +% \bigstrutjot to .5\jot. Then simply repeat nrows as the bigstruts argument. +% This will be close, but probably not exact; you can use the fixup argument +% to refine the result. (If you do this repeatedly, you'll probably want to +% wrap these steps up in a simple macro. Note that the modified \bigstrutjot +% value will not give reasonable results if you have bigstruts and use this +% argument for its intended purpose elsewhere. In that case, you might want +% to set it locally.) +% +% If you use \multirow with the colortbl package you have to take +% precautions if you want to color the column that has the \multirow in it. +% colortbl works by coloring each cell separately. So if you use \multirow +% with a positive nrows value, colortbl will first color the top cell, then +% \multirow will typeset nrows cells starting with this cell, and later +% colortbl will color the other cells, effectively hiding the text in that +% area. This can be solved by putting the \multirow is the last row with a +% negative nrows value. +% Example: +% +% \begin{tabular}{l>{\columncolor{yellow}}l} +% aaaa & \\ +% cccc & \\ +% dddd & \multirow{-3}*{bbbb}\\ +% \end{tabular} +% +\def\multirowsetup{\raggedright} +\def\multirow#1{\relax\@ifnextchar + [{\@multirow{#1}}{\@multirow{#1}[0]}} +\def\@multirow#1[#2]#3{\@ifnextchar [{\@xmultirow{#1}[#2]{#3}}% + {\@xmultirow{#1}[#2]{#3}[0pt]}} +\def\@xmultirow#1[#2]#3[#4]#5{\@tempcnta=#1% + \@tempdima\@tempcnta\ht\@arstrutbox + \advance\@tempdima\@tempcnta\dp\@arstrutbox + \ifnum\@tempcnta<0\@tempdima=-\@tempdima\fi + \advance\@tempdima#2\bigstrutjot + \if*#3\setbox0\vtop to \@tempdima{\vfill\multirowsetup + \hbox{\strut#5\strut}\vfill}% + \else + \setbox0\vtop to \@tempdima{\hsize#3\@parboxrestore + \vfill \multirowsetup \strut#5\strut\par\vfill}% + \fi + \ht0\z@\dp0\z@ + \ifnum\@tempcnta<0\advance\@tempdima-\dp\@arstrutbox + \else\@tempdima=\ht\@arstrutbox + \ifnum#2>0 \advance\@tempdima\bigstrutjot \fi + \fi + \advance\@tempdima#4\relax\leavevmode\vtop{\vskip-\@tempdima\box0\vss}} +\@ifundefined{bigstrutjot}{\newdimen\bigstrutjot \bigstrutjot\jot}{} diff --git a/resources/latex/tocloft.sty b/resources/latex/tocloft.sty new file mode 100644 index 00000000..3f8b7d26 --- /dev/null +++ b/resources/latex/tocloft.sty @@ -0,0 +1,1110 @@ +%% +%% This is file `tocloft.sty', +%% generated with the docstrip utility. +%% +%% The original source files were: +%% +%% tocloft.dtx (with options: `usc') +%% +%% Author: Peter Wilson, Herries Press +%% Maintainer: Will Robertson (will dot robertson at latex-project dot org) +%% Maintainer: Will Robertson (will dot robertson at latex-project dot org) +%% Copyright 1998-2003 Peter R. Wilson +%% Copyright 2009 Will Robertson +%% +%% This work may be distributed and/or modified under the +%% conditions of the LaTeX Project Public License, either +%% version 1.3c of this license or (at your option) any +%% later version: +%% +%% This work has the LPPL maintenance status "maintained". +%% The Current Maintainer of this work is Will Robertson. +%% +%% This work consists of the files listed in the README file. +%% +\NeedsTeXFormat{LaTeX2e} +\ProvidesPackage{tocloft}[2009/09/04 v2.3d parameterised ToC, etc., typesetting] +\providecommand{\PRWPackageNote}[2]{% + \GenericWarning{% + (#1)\@spaces\@spaces\@spaces\@spaces + }{% + Package #1 Note: #2% + }% +} +\providecommand{\PRWPackageNoteNoLine}[2]{% + \PRWPackageNote{#1}{#2\@gobble}% +} +\newcommand{\@cftquit}{} +\newif\if@cfthaschapter +\newif\if@cftkoma + \@cftkomafalse +\@ifclassloaded{scrartcl}{\@cftkomatrue}{} +\@ifclassloaded{scrreprt}{\@cftkomatrue}{} +\@ifclassloaded{scrbook}{\@cftkomatrue}{} + +\@ifundefined{chapter}{% + \@cfthaschapterfalse + \@ifundefined{section}{% + \PackageWarning{tocloft}% + {I don't recognize any sectional divisions so I'll do nothing} + \renewcommand{\@cftquit}{\endinput} + }{\PRWPackageNoteNoLine{tocloft}{The document has section divisions}} + }{\@cfthaschaptertrue + \PRWPackageNoteNoLine{tocloft}{The document has chapter divisions}} +\@cftquit +\newif\if@cfttocbibind +\AtBeginDocument{% + \@ifpackageloaded{tocbibind}{\@cfttocbibindtrue}{\@cfttocbibindfalse} + \if@cfttocbibind + \@ifpackagelater{tocbibind}{1998/11/16}{}{% + \PackageWarning{tocloft}{% +You are using a version of the tocbibind package\MessageBreak +that is not compatible with tocloft.\MessageBreak +The results may be surprising.\MessageBreak +Consider installing the current version of tocbibind.}} + \fi +} +\newif\if@cftnctoc\@cftnctocfalse +\DeclareOption{titles}{\@cftnctoctrue} + %% \ProcessOptions\relax +\newif\if@cftsubfigopt\@cftsubfigoptfalse +\DeclareOption{subfigure}{\@cftsubfigopttrue} + +\ProcessOptions\relax + +\newcommand{\tocloftpagestyle}[1]{% + \def\@cftpagestyle{\thispagestyle{#1}}} +\tocloftpagestyle{plain} + +\newcommand{\cftmarktoc}{% + \@mkboth{\MakeUppercase\contentsname}{\MakeUppercase\contentsname}} +\newcommand{\cftmarklof}{% + \@mkboth{\MakeUppercase\listfigurename}{\MakeUppercase\listfigurename}} +\newcommand{\cftmarklot}{% + \@mkboth{\MakeUppercase\listtablename}{\MakeUppercase\listtablename}} +\if@cftkoma + \renewcommand{\cftmarktoc}{% + \@mkboth{\contentsname}{\contentsname}} + \renewcommand{\cftmarklof}{% + \@mkboth{\listfigurename}{\listfigurename}} + \renewcommand{\cftmarklot}{% + \@mkboth{\listtablename}{\listtablename}} +\fi +\providecommand{\@cfttocstart}{% + \if@cfthaschapter + \if@twocolumn + \@restonecoltrue\onecolumn + \else + \@restonecolfalse + \fi + \fi} +\providecommand{\@cfttocfinish}{% + \if@cfthaschapter + \if@restonecol\twocolumn\fi + \fi} +\providecommand{\phantomsection}{} + +\newcommand{\@cftdobibtoc}{% + \if@dotoctoc + \if@bibchapter + \phantomsection + \addcontentsline{toc}{chapter}{\contentsname} + \else + \phantomsection + \addcontentsline{toc}{\@tocextra}{\contentsname} + \fi + \fi} + +\newlength{\cftparskip} +\setlength{\cftparskip}{0pt} + +\AtBeginDocument{% +\if@cftnctoc\else + \renewcommand{\tableofcontents}{% + \@cfttocstart + \par + \begingroup + \parindent\z@ \parskip\cftparskip + \@cftmaketoctitle + \if@cfttocbibind + \@cftdobibtoc + \fi + \@starttoc{toc}% + \endgroup + \@cfttocfinish} +\fi +} +\newcommand{\@cftmaketoctitle}{% + \addpenalty\@secpenalty + \if@cfthaschapter + \vspace*{\cftbeforetoctitleskip} + \else + \vspace{\cftbeforetoctitleskip} + \fi + \@cftpagestyle + {\interlinepenalty\@M + {\cfttoctitlefont\contentsname}{\cftaftertoctitle} + \cftmarktoc + \par\nobreak + \vskip \cftaftertoctitleskip + \@afterheading}} +\newlength{\cftbeforetoctitleskip} +\newlength{\cftaftertoctitleskip} +\if@cfthaschapter + \setlength{\cftbeforetoctitleskip}{50pt} + \setlength{\cftaftertoctitleskip}{40pt} +\else + \setlength{\cftbeforetoctitleskip}{3.5ex \@plus 1ex \@minus .2ex} + \setlength{\cftaftertoctitleskip}{2.3ex \@plus.2ex} +\fi +\if@cfthaschapter + \newcommand{\cfttoctitlefont}{\normalfont\Huge\bfseries} + \if@cftkoma\renewcommand{\cfttoctitlefont}{\size@chapter\sectfont}\fi +\else + \newcommand{\cfttoctitlefont}{\normalfont\Large\bfseries} + \if@cftkoma\renewcommand{\cfttoctitlefont}{\size@section\sectfont}\fi +\fi +\newcommand{\cftaftertoctitle}{} +\newcommand{\cftsetpnumwidth}[1]{\renewcommand{\@pnumwidth}{#1}} +\newcommand{\cftsetrmarg}[1]{\renewcommand{\@tocrmarg}{#1}} +\providecommand{\cftdot}{.} +\providecommand{\cftdotfill}[1]{% + \leaders\hbox{$\m@th\mkern #1 mu\hbox{\cftdot}\mkern #1 mu$}\hfill} +\providecommand{\cftdotsep}{4.5} +\newcommand{\cftnodots}{10000} +\newcommand{\cftparfillskip}{\parfillskip=0pt plus1fil} +\renewcommand{\numberline}[1]{% + \hb@xt@\@tempdima{\@cftbsnum #1\@cftasnum\hfil}\@cftasnumb} +\newcommand{\@cftbsnum}{} +\newcommand{\@cftasnum}{} +\newcommand{\@cftasnumb}{} +\newif\if@cftdopart +\newif\if@cfthaspart +\@ifundefined{part}{\@cfthaspartfalse}{\@cfthasparttrue} +\if@cfthaspart +\renewcommand*{\l@part}[2]{% + \@cftdopartfalse + \ifnum \c@tocdepth >-2\relax + \if@cfthaschapter + \@cftdoparttrue + \fi + \ifnum \c@tocdepth >\m@ne + \if@cfthaschapter\else + \@cftdoparttrue + \fi + \fi + \fi + \if@cftdopart + \if@cfthaschapter + \addpenalty{-\@highpenalty}% + \else + \addpenalty\@secpenalty + \fi + \addvspace{\cftbeforepartskip}% + \begingroup + {\leftskip \cftpartindent\relax + \rightskip \@tocrmarg + \parfillskip -\rightskip + \parindent \cftpartindent\relax\@afterindenttrue + \interlinepenalty\@M + \leavevmode + \@tempdima \cftpartnumwidth\relax + \let\@cftbsnum \cftpartpresnum + \let\@cftasnum \cftpartaftersnum + \let\@cftasnumb \cftpartaftersnumb + \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip + {\cftpartfont \cftpartpresnum #1}% + \cftpartfillnum{#2}} + \nobreak + \if@cfthaschapter + \global\@nobreaktrue + \everypar{\global\@nobreakfalse\everypar{}}% + \else + \if@compatibility + \global\@nobreaktrue + \everypar{\global\@nobreakfalse\everypar{}}% + \fi + \fi + \endgroup + \fi} +\fi +\if@cfthaspart + \newlength{\cftbeforepartskip} + \setlength{\cftbeforepartskip}{2.25em \@plus\p@} + \newlength{\cftpartnumwidth} + \setlength{\cftpartnumwidth}{0em} + \newcommand{\cftpartfont}{\large\bfseries} + \newcommand{\cftpartpresnum}{} + \newcommand{\cftpartaftersnum}{} + \newcommand{\cftpartaftersnumb}{} + \newcommand{\cftpartleader}{\large\bfseries\cftdotfill{\cftpartdotsep}} + \newcommand{\cftpartdotsep}{\cftnodots} + \newcommand{\cftpartpagefont}{\large\bfseries} + \newcommand{\cftpartafterpnum}{} + \newlength{\cftpartindent} + \setlength{\cftpartindent}{0em} + \newcommand{\cftpartfillnum}[1]{% + {\cftpartleader}% + {\hb@xt@\@pnumwidth{\hss {\cftpartpagefont #1}}}\cftpartafterpnum\par} + \if@cftkoma + \setlength{\cftpartnumwidth}{2em} + \renewcommand{\cftpartfont}{\sectfont\large} + \renewcommand{\cftpartpagefont}{\sectfont\large} + \fi +\fi + +\if@cfthaschapter +\renewcommand*{\l@chapter}[2]{% + \ifnum \c@tocdepth >\m@ne + \addpenalty{-\@highpenalty}% + \vskip \cftbeforechapskip + {\leftskip \cftchapindent\relax + \rightskip \@tocrmarg + \parfillskip -\rightskip + \parindent \cftchapindent\relax\@afterindenttrue + \interlinepenalty\@M + \leavevmode + \@tempdima \cftchapnumwidth\relax + \let\@cftbsnum \cftchappresnum + \let\@cftasnum \cftchapaftersnum + \let\@cftasnumb \cftchapaftersnumb + \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip + {\cftchapfont #1}\nobreak + \cftchapfillnum{#2}}% + \fi}% +\fi +\if@cfthaschapter + \newlength{\cftbeforechapskip} + \setlength{\cftbeforechapskip}{1.0em \@plus\p@} + \newlength{\cftchapindent} + \setlength{\cftchapindent}{0em} + \newlength{\cftchapnumwidth} + \setlength{\cftchapnumwidth}{1.5em} + \newcommand{\cftchapfont}{\bfseries} + \newcommand{\cftchappresnum}{} + \newcommand{\cftchapaftersnum}{} + \newcommand{\cftchapaftersnumb}{} + \newcommand{\cftchapleader}{\bfseries\cftdotfill{\cftchapdotsep}} + \newcommand{\cftchapdotsep}{\cftnodots} + \newcommand{\cftchappagefont}{\bfseries} + \newcommand{\cftchapafterpnum}{} + \newcommand{\cftchapfillnum}[1]{% + {\cftchapleader}\nobreak + \hb@xt@\@pnumwidth{\hfil\cftchappagefont #1}\cftchapafterpnum\par} + \if@cftkoma + \renewcommand{\cftchapfont}{\sectfont} + \fi +\fi + +\renewcommand*{\l@section}[2]{% + \ifnum \c@tocdepth >\z@ + \if@cfthaschapter + \vskip \cftbeforesecskip + \else + \addpenalty\@secpenalty + \addvspace{\cftbeforesecskip} + \fi + {\leftskip \cftsecindent\relax + \rightskip \@tocrmarg + \parfillskip -\rightskip + \parindent \cftsecindent\relax\@afterindenttrue + \interlinepenalty\@M + \leavevmode + \@tempdima \cftsecnumwidth\relax + \let\@cftbsnum \cftsecpresnum + \let\@cftasnum \cftsecaftersnum + \let\@cftasnumb \cftsecaftersnumb + \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip + {\cftsecfont #1}\nobreak + \cftsecfillnum{#2}}% + \fi} +\newlength{\cftbeforesecskip} +\newlength{\cftsecindent} +\newlength{\cftsecnumwidth} +\newcommand{\cftsecpresnum}{} +\newcommand{\cftsecaftersnum}{} +\newcommand{\cftsecaftersnumb}{} +\if@cfthaschapter + \setlength{\cftbeforesecskip}{\z@ \@plus.2\p@} + \setlength{\cftsecindent}{1.5em} + \setlength{\cftsecnumwidth}{2.3em} + \newcommand{\cftsecfont}{\normalfont} + \newcommand{\cftsecleader}{\normalfont\cftdotfill{\cftsecdotsep}} + \newcommand{\cftsecdotsep}{\cftdotsep} + \newcommand{\cftsecpagefont}{\normalfont} +\else + \setlength{\cftbeforesecskip}{1.0em \@plus\p@} + \setlength{\cftsecindent}{0em} + \setlength{\cftsecnumwidth}{1.5em} + \newcommand{\cftsecfont}{\bfseries} + \newcommand{\cftsecleader}{\bfseries\cftdotfill{\cftsecdotsep}} + \newcommand{\cftsecdotsep}{\cftnodots} + \newcommand{\cftsecpagefont}{\bfseries} +\fi +\newcommand{\cftsecafterpnum}{} +\newcommand{\cftsecfillnum}[1]{% + {\cftsecleader}\nobreak + \hb@xt@\@pnumwidth{\hfil\cftsecpagefont #1}\cftsecafterpnum\par} + +\renewcommand*{\l@subsection}[2]{% + \ifnum \c@tocdepth >\@ne + \vskip \cftbeforesubsecskip + {\leftskip \cftsubsecindent\relax + \rightskip \@tocrmarg + \parfillskip -\rightskip + \parindent \cftsubsecindent\relax\@afterindenttrue + \interlinepenalty\@M + \leavevmode + \@tempdima \cftsubsecnumwidth\relax + \let\@cftbsnum \cftsubsecpresnum + \let\@cftasnum \cftsubsecaftersnum + \let\@cftasnumb \cftsubsecaftersnumb + \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip + {\cftsubsecfont #1}\nobreak + \cftsubsecfillnum{#2}}% + \fi} +\newlength{\cftbeforesubsecskip} + \setlength{\cftbeforesubsecskip}{\z@ \@plus.2\p@} +\newlength{\cftsubsecindent} +\newlength{\cftsubsecnumwidth} +\if@cfthaschapter + \setlength{\cftsubsecindent}{3.8em} + \setlength{\cftsubsecnumwidth}{3.2em} +\else + \setlength{\cftsubsecindent}{1.5em} + \setlength{\cftsubsecnumwidth}{2.3em} +\fi +\newcommand{\cftsubsecfont}{\normalfont} +\newcommand{\cftsubsecpresnum}{} +\newcommand{\cftsubsecaftersnum}{} +\newcommand{\cftsubsecaftersnumb}{} +\newcommand{\cftsubsecleader}{\normalfont\cftdotfill{\cftsubsecdotsep}} +\newcommand{\cftsubsecdotsep}{\cftdotsep} +\newcommand{\cftsubsecpagefont}{\normalfont} +\newcommand{\cftsubsecafterpnum}{} +\newcommand{\cftsubsecfillnum}[1]{% + {\cftsubsecleader}\nobreak + \hb@xt@\@pnumwidth{\hfil\cftsubsecpagefont #1}\cftsubsecafterpnum\par} + +\renewcommand*{\l@subsubsection}[2]{% + \ifnum \c@tocdepth >\tw@ + \vskip \cftbeforesubsubsecskip + {\leftskip \cftsubsubsecindent\relax + \rightskip \@tocrmarg + \parfillskip -\rightskip + \parindent \cftsubsubsecindent\relax\@afterindenttrue + \interlinepenalty\@M + \leavevmode + \@tempdima \cftsubsubsecnumwidth\relax + \let\@cftbsnum \cftsubsubsecpresnum + \let\@cftasnum \cftsubsubsecaftersnum + \let\@cftasnumb \cftsubsubsecaftersnumb + \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip + {\cftsubsubsecfont #1}\nobreak + \cftsubsubsecfillnum{#2}}% + \fi} +\newlength{\cftbeforesubsubsecskip} + \setlength{\cftbeforesubsubsecskip}{\z@ \@plus.2\p@} +\newlength{\cftsubsubsecindent} +\newlength{\cftsubsubsecnumwidth} +\if@cfthaschapter + \setlength{\cftsubsubsecindent}{7.0em} + \setlength{\cftsubsubsecnumwidth}{4.1em} +\else + \setlength{\cftsubsubsecindent}{3.8em} + \setlength{\cftsubsubsecnumwidth}{3.2em} +\fi +\newcommand{\cftsubsubsecfont}{\normalfont} +\newcommand{\cftsubsubsecpresnum}{} +\newcommand{\cftsubsubsecaftersnum}{} +\newcommand{\cftsubsubsecaftersnumb}{} +\newcommand{\cftsubsubsecleader}{\normalfont\cftdotfill{\cftsubsubsecdotsep}} +\newcommand{\cftsubsubsecdotsep}{\cftdotsep} +\newcommand{\cftsubsubsecpagefont}{\normalfont} +\newcommand{\cftsubsubsecafterpnum}{} +\newcommand{\cftsubsubsecfillnum}[1]{% + {\cftsubsubsecleader}\nobreak + \hb@xt@\@pnumwidth{\hfil\cftsubsubsecpagefont #1}\cftsubsubsecafterpnum\par} + +\renewcommand*{\l@paragraph}[2]{% + \ifnum \c@tocdepth >3\relax + \vskip \cftbeforeparaskip + {\leftskip \cftparaindent\relax + \rightskip \@tocrmarg + \parfillskip -\rightskip + \parindent \cftparaindent\relax\@afterindenttrue + \interlinepenalty\@M + \leavevmode + \@tempdima \cftparanumwidth\relax + \let\@cftbsnum \cftparapresnum + \let\@cftasnum \cftparaaftersnum + \let\@cftasnumb \cftparaaftersnumb + \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip + {\cftparafont #1}\nobreak + \cftparafillnum{#2}}% + \fi} +\newlength{\cftbeforeparaskip} + \setlength{\cftbeforeparaskip}{\z@ \@plus.2\p@} +\newlength{\cftparaindent} +\newlength{\cftparanumwidth} +\if@cfthaschapter + \setlength{\cftparaindent}{10em} + \setlength{\cftparanumwidth}{5em} +\else + \setlength{\cftparaindent}{7.0em} + \setlength{\cftparanumwidth}{4.1em} +\fi +\newcommand{\cftparafont}{\normalfont} +\newcommand{\cftparapresnum}{} +\newcommand{\cftparaaftersnum}{} +\newcommand{\cftparaaftersnumb}{} +\newcommand{\cftparaleader}{\normalfont\cftdotfill{\cftparadotsep}} +\newcommand{\cftparadotsep}{\cftdotsep} +\newcommand{\cftparapagefont}{\normalfont} +\newcommand{\cftparaafterpnum}{} +\newcommand{\cftparafillnum}[1]{% + {\cftparaleader}\nobreak + \hb@xt@\@pnumwidth{\hfil\cftparapagefont #1}\cftparaafterpnum\par} + +\renewcommand*{\l@subparagraph}[2]{% + \ifnum \c@tocdepth >4\relax + \vskip \cftbeforesubparaskip + {\leftskip \cftsubparaindent\relax + \rightskip \@tocrmarg + \parfillskip -\rightskip + \parindent \cftsubparaindent\relax\@afterindenttrue + \interlinepenalty\@M + \leavevmode + \@tempdima \cftsubparanumwidth\relax + \let\@cftbsnum \cftsubparapresnum + \let\@cftasnum \cftsubparaaftersnum + \let\@cftasnumb \cftsubparaaftersnumb + \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip + {\cftsubparafont #1}\nobreak + \cftsubparafillnum{#2}}% + \fi} +\newlength{\cftbeforesubparaskip} + \setlength{\cftbeforesubparaskip}{\z@ \@plus.2\p@} +\newlength{\cftsubparaindent} +\newlength{\cftsubparanumwidth} +\if@cfthaschapter + \setlength{\cftsubparaindent}{12em} + \setlength{\cftsubparanumwidth}{6em} +\else + \setlength{\cftsubparaindent}{10em} + \setlength{\cftsubparanumwidth}{5em} +\fi +\newcommand{\cftsubparafont}{\normalfont} +\newcommand{\cftsubparapresnum}{} +\newcommand{\cftsubparaaftersnum}{} +\newcommand{\cftsubparaaftersnumb}{} +\newcommand{\cftsubparaleader}{\normalfont\cftdotfill{\cftsubparadotsep}} +\newcommand{\cftsubparadotsep}{\cftdotsep} +\newcommand{\cftsubparapagefont}{\normalfont} +\newcommand{\cftsubparaafterpnum}{} +\newcommand{\cftsubparafillnum}[1]{% + {\cftsubparaleader}\nobreak + \hb@xt@\@pnumwidth{\hfil\cftsubparapagefont #1}\cftsubparaafterpnum\par} + +\newcommand{\@cftdobiblof}{% + \if@dotoclof + \if@bibchapter + \phantomsection + \addcontentsline{toc}{chapter}{\listfigurename} + \else + \phantomsection + \addcontentsline{toc}{\@tocextra}{\listfigurename} + \fi + \fi} + +\AtBeginDocument{% +\if@cftnctoc\else +\renewcommand{\listoffigures}{% + \@cfttocstart + \par + \begingroup + \parindent\z@ \parskip\cftparskip + \@cftmakeloftitle + \if@cfttocbibind + \@cftdobiblof + \fi + \@starttoc{lof}% + \endgroup + \@cfttocfinish}% +\fi +} + +\newcommand{\@cftmakeloftitle}{% + \addpenalty\@secpenalty + \if@cfthaschapter + \vspace*{\cftbeforeloftitleskip} + \else + \vspace{\cftbeforeloftitleskip} + \fi + \@cftpagestyle + {\interlinepenalty\@M + {\cftloftitlefont\listfigurename}{\cftafterloftitle} + \cftmarklof + \par\nobreak + \vskip \cftafterloftitleskip + \@afterheading}} + +\newlength{\cftbeforeloftitleskip} +\newlength{\cftafterloftitleskip} +\if@cfthaschapter + \setlength{\cftbeforeloftitleskip}{50pt} + \setlength{\cftafterloftitleskip}{40pt} +\else + \setlength{\cftbeforeloftitleskip}{3.5ex \@plus 1ex \@minus .2ex} + \setlength{\cftafterloftitleskip}{2.3ex \@plus.2ex} +\fi +\if@cfthaschapter + \newcommand{\cftloftitlefont}{\normalfont\Huge\bfseries} + \if@cftkoma\renewcommand{\cftloftitlefont}{\size@chapter\sectfont}\fi +\else + \newcommand{\cftloftitlefont}{\normalfont\Large\bfseries} + \if@cftkoma\renewcommand{\cftloftitlefont}{\size@section\sectfont}\fi +\fi +\newcommand{\cftafterloftitle}{} + +\renewcommand*{\l@figure}[2]{% + \ifnum \c@lofdepth >\z@ + \vskip \cftbeforefigskip + {\leftskip \cftfigindent\relax + \rightskip \@tocrmarg + \parfillskip -\rightskip + \parindent \cftfigindent\relax\@afterindenttrue + \interlinepenalty\@M + \leavevmode + \@tempdima \cftfignumwidth\relax + \let\@cftbsnum \cftfigpresnum + \let\@cftasnum \cftfigaftersnum + \let\@cftasnumb \cftfigaftersnumb + \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip + {\cftfigfont #1}\nobreak + \cftfigfillnum{#2}}% + \fi + } +\newlength{\cftbeforefigskip} + \setlength{\cftbeforefigskip}{\z@ \@plus.2\p@} +\newlength{\cftfigindent} + \setlength{\cftfigindent}{1.5em} +\newlength{\cftfignumwidth} + \setlength{\cftfignumwidth}{2.3em} +\newcommand{\cftfigfont}{\normalfont} +\newcommand{\cftfigpresnum}{} +\newcommand{\cftfigaftersnum}{} +\newcommand{\cftfigaftersnumb}{} +\newcommand{\cftfigleader}{\normalfont\cftdotfill{\cftfigdotsep}} +\newcommand{\cftfigdotsep}{\cftdotsep} +\newcommand{\cftfigpagefont}{\normalfont} +\newcommand{\cftfigafterpnum}{} +\newcommand{\cftfigfillnum}[1]{% + {\cftfigleader}\nobreak + \hb@xt@\@pnumwidth{\hfil\cftfigpagefont #1}\cftfigafterpnum\par} + +\if@cftsubfigopt\else + \newcounter{lofdepth}\setcounter{lofdepth}{1} + \newcounter{lotdepth}\setcounter{lotdepth}{1} +\fi + +\newcommand{\@cftdobiblot}{% + \if@dotoclot + \if@bibchapter + \phantomsection + \addcontentsline{toc}{chapter}{\listtablename} + \else + \phantomsection + \addcontentsline{toc}{\@tocextra}{\listtablename} + \fi + \fi} + +\AtBeginDocument{% +\if@cftnctoc\else +\renewcommand{\listoftables}{% + \@cfttocstart + \par + \begingroup + \parindent\z@ \parskip\cftparskip + \@cftmakelottitle + \if@cfttocbibind + \@cftdobiblot + \fi + \@starttoc{lot}% + \endgroup + \@cfttocfinish}% +\fi +} + +\newcommand{\@cftmakelottitle}{% + \addpenalty\@secpenalty + \if@cfthaschapter + \vspace*{\cftbeforelottitleskip} + \else + \vspace{\cftbeforelottitleskip} + \fi + \@cftpagestyle + {\interlinepenalty\@M + {\cftlottitlefont\listtablename}{\cftafterlottitle} + \cftmarklot + \par\nobreak + \vskip \cftafterlottitleskip + \@afterheading}} + +\newlength{\cftbeforelottitleskip} +\newlength{\cftafterlottitleskip} +\if@cfthaschapter + \setlength{\cftbeforelottitleskip}{50pt} + \setlength{\cftafterlottitleskip}{40pt} +\else + \setlength{\cftbeforelottitleskip}{3.5ex \@plus 1ex \@minus .2ex} + \setlength{\cftafterlottitleskip}{2.3ex \@plus.2ex} +\fi +\if@cfthaschapter + \newcommand{\cftlottitlefont}{\normalfont\Huge\bfseries} + \if@cftkoma\renewcommand{\cftlottitlefont}{\size@chapter\sectfont}\fi +\else + \newcommand{\cftlottitlefont}{\normalfont\Large\bfseries} + \if@cftkoma\renewcommand{\cftlottitlefont}{\size@section\sectfont}\fi +\fi +\newcommand{\cftafterlottitle}{} + +\renewcommand*{\l@table}[2]{% + \ifnum\c@lotdepth >\z@ + \vskip \cftbeforetabskip + {\leftskip \cfttabindent\relax + \rightskip \@tocrmarg + \parfillskip -\rightskip + \parindent \cfttabindent\relax\@afterindenttrue + \interlinepenalty\@M + \leavevmode + \@tempdima \cfttabnumwidth\relax + \let\@cftbsnum \cfttabpresnum + \let\@cftasnum \cfttabaftersnum + \let\@cftasnumb \cfttabaftersnumb + \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip + {\cfttabfont #1}\nobreak + \cfttabfillnum{#2}}% + \fi + } +\newlength{\cftbeforetabskip} + \setlength{\cftbeforetabskip}{\z@ \@plus.2\p@} +\newlength{\cfttabindent} + \setlength{\cfttabindent}{1.5em} +\newlength{\cfttabnumwidth} + \setlength{\cfttabnumwidth}{2.3em} +\newcommand{\cfttabfont}{\normalfont} +\newcommand{\cfttabpresnum}{} +\newcommand{\cfttabaftersnum}{} +\newcommand{\cfttabaftersnumb}{} +\newcommand{\cfttableader}{\normalfont\cftdotfill{\cfttabdotsep}} +\newcommand{\cfttabdotsep}{\cftdotsep} +\newcommand{\cfttabpagefont}{\normalfont} +\newcommand{\cfttabafterpnum}{} +\newcommand{\cfttabfillnum}[1]{% + {\cfttableader}\nobreak + \hb@xt@\@pnumwidth{\hfil\cfttabpagefont #1}\cfttabafterpnum\par} + +\newcommand{\@cftl@subfig}{% +\renewcommand*{\l@subfigure}[2]{% + \ifnum \c@lofdepth > \toclevel@subfigure + \vskip \cftbeforesubfigskip + {\leftskip \cftsubfigindent\relax + \rightskip \@tocrmarg + \parfillskip -\rightskip + \parindent \cftsubfigindent\relax\@afterindenttrue + \interlinepenalty\@M + \leavevmode + \@tempdima \cftsubfignumwidth\relax + \let\@cftbsnum \cftsubfigpresnum + \let\@cftasnum \cftsubfigaftersnum + \let\@cftasnumb \cftsubfigaftersnumb + \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip + {\cftsubfigfont ##1}\nobreak + \cftsubfigfillnum{##2}}% + \fi + }% +} + +\newcommand{\@cftsetsubfig}{% +\newlength{\cftbeforesubfigskip} + \setlength{\cftbeforesubfigskip}{\z@ \@plus.2\p@} +\newlength{\cftsubfigindent} + \setlength{\cftsubfigindent}{3.8em} +\newlength{\cftsubfignumwidth} + \setlength{\cftsubfignumwidth}{2.5em} +\newcommand{\cftsubfigfont}{\normalfont} +\newcommand{\cftsubfigpresnum}{} +\newcommand{\cftsubfigaftersnum}{} +\newcommand{\cftsubfigaftersnumb}{} +\newcommand{\cftsubfigleader}{\normalfont\cftdotfill{\cftsubtabdotsep}} +\newcommand{\cftsubfigdotsep}{\cftdotsep} +\newcommand{\cftsubfigpagefont}{\normalfont} +\newcommand{\cftsubfigafterpnum}{} +\providecommand{\toclevel@subfigure}{1} +\newcommand{\cftsubfigfillnum}[1]{% + {\cftsubfigleader}\nobreak + \hb@xt@\@pnumwidth{\hfil\cftsubfigpagefont ##1}\cftsubfigafterpnum\par} +} + +\newcommand{\@cftl@subtab}{% +\renewcommand*{\l@subtable}[2]{% + \ifnum \c@lotdepth > \toclevel@subtable + \vskip \cftbeforesubtabskip + {\leftskip \cftsubtabindent\relax + \rightskip \@tocrmarg + \parfillskip -\rightskip + \parindent \cftsubtabindent\relax\@afterindenttrue + \interlinepenalty\@M + \leavevmode + \@tempdima \cftsubtabnumwidth\relax + \let\@cftbsnum \cftsubtabpresnum + \let\@cftasnum \cftsubtabaftersnum + \let\@cftasnumb \cftsubtabaftersnumb + \advance\leftskip \@tempdima \null\nobreak\hskip -\leftskip + {\cftsubtabfont ##1}\nobreak + \cftsubtabfillnum{##2}}% + \fi + }% +} +\newcommand{\@cftsetsubtab}{% +\newlength{\cftbeforesubtabskip} + \setlength{\cftbeforesubtabskip}{\z@ \@plus.2\p@} +\newlength{\cftsubtabindent} + \setlength{\cftsubtabindent}{3.8em} +\newlength{\cftsubtabnumwidth} + \setlength{\cftsubtabnumwidth}{2.5em} +\newcommand{\cftsubtabfont}{\normalfont} +\newcommand{\cftsubtabpresnum}{} +\newcommand{\cftsubtabaftersnum}{} +\newcommand{\cftsubtabaftersnumb}{} +\newcommand{\cftsubtableader}{\normalfont\cftdotfill{\cftsubtabdotsep}} +\newcommand{\cftsubtabdotsep}{\cftdotsep} +\newcommand{\cftsubtabpagefont}{\normalfont} +\newcommand{\cftsubtabafterpnum}{} +\providecommand{\toclevel@subtable}{1} +\newcommand{\cftsubtabfillnum}[1]{% + {\cftsubtableader}\nobreak + \hb@xt@\@pnumwidth{\hfil\cftsubtabpagefont ##1}\cftsubtabafterpnum\par} +} + + +\if@cftsubfigopt + \@cftsetsubfig\@cftsetsubtab + \AtBeginDocument{\@cftl@subfig\@cftl@subtab} +\fi +%% \AtBeginDocument{\if@cftsubfigopt +%% \@cftsetsubfig\@cftsetsubtab +%% \@cftl@subfig\@cftl@subtab +%% \fi} + +\newcommand{\newlistentry}[4][\@empty]{% + \@ifundefined{c@#2}{% check & set the counter + \ifx \@empty#1\relax + \newcounter{#2} + \else + \@ifundefined{c@#1}{\PackageWarning{tocloft}% + {#1 has no counter for use as a `within'} + \newcounter{#2}}% + {\newcounter{#2}[#1]% + \expandafter\edef\csname the#2\endcsname{% + \expandafter\noexpand\csname the#1\endcsname.\noexpand\arabic{#2}}} + \fi + \setcounter{#2}{0} + } + {\PackageError{tocloft}{#2 has been previously defined}{\@eha}} + + \@namedef{l@#2}##1##2{% + \ifnum \@nameuse{c@#3depth} > #4\relax + \vskip \@nameuse{cftbefore#2skip} + {\leftskip \@nameuse{cft#2indent}\relax + \rightskip \@tocrmarg + \parfillskip -\rightskip + \parindent \@nameuse{cft#2indent}\relax\@afterindenttrue + \interlinepenalty\@M + \leavevmode + \@tempdima \@nameuse{cft#2numwidth}\relax + \expandafter\let\expandafter\@cftbsnum\csname cft#2presnum\endcsname + \expandafter\let\expandafter\@cftasnum\csname cft#2aftersnum\endcsname + \expandafter\let\expandafter\@cftasnumb\csname cft#2aftersnumb\endcsname + \advance\leftskip\@tempdima \null\nobreak\hskip -\leftskip + {\@nameuse{cft#2font}##1}\nobreak + \@nameuse{cft#2fillnum}{##2}}% + \fi + } % end of \l@#2 + + \expandafter\newlength\csname cftbefore#2skip\endcsname + \setlength{\@nameuse{cftbefore#2skip}}{\z@ \@plus .2\p@} + \expandafter\newlength\csname cft#2indent\endcsname + \expandafter\newlength\csname cft#2numwidth\endcsname + \ifcase #4\relax % 0 + \setlength{\@nameuse{cft#2indent}}{0em} + \setlength{\@nameuse{cft#2numwidth}}{1.5em} + \or % 1 + \setlength{\@nameuse{cft#2indent}}{1.5em} + \setlength{\@nameuse{cft#2numwidth}}{2.3em} + \or % 2 + \setlength{\@nameuse{cft#2indent}}{3.8em} + \setlength{\@nameuse{cft#2numwidth}}{3.2em} + \or % 3 + \setlength{\@nameuse{cft#2indent}}{7.0em} + \setlength{\@nameuse{cft#2numwidth}}{4.1em} + \else % anything else + \setlength{\@nameuse{cft#2indent}}{10.0em} + \setlength{\@nameuse{cft#2numwidth}}{5.0em} + \fi + \@namedef{cft#2font}{\normalfont} + \@namedef{cft#2presnum}{} + \@namedef{cft#2aftersnum}{} + \@namedef{cft#2aftersnumb}{} + \@namedef{cft#2dotsep}{\cftdotsep} + \@namedef{cft#2leader}{\normalfont\cftdotfill{\@nameuse{cft#2dotsep}}} + \@namedef{cft#2pagefont}{\normalfont} + \@namedef{cft#2afterpnum}{} + \@namedef{toclevel@#2}{#4} + \@namedef{cft#2fillnum}##1{% + {\@nameuse{cft#2leader}}\nobreak + \hb@xt@\@pnumwidth{\hfil\@nameuse{cft#2pagefont}##1}\@nameuse{cft#2afterpnum}\par} +} % end \newlistentry + +\newcommand{\newlistof}[4][\@empty]{% + \ifx \@empty#1\relax + \newlistentry{#2}{#3}{0} + \else + \newlistentry[#1]{#2}{#3}{0} + \fi + + \@namedef{ext@#3}{#3} + \newcounter{#3depth} + \setcounter{#3depth}{1} + + \if@cftkoma + \@namedef{cftmark#3}{% + \@mkboth{#4}{#4}} + \else + \@namedef{cftmark#3}{% + \@mkboth{\MakeUppercase{#4}}{\MakeUppercase{#4}}} + \fi + \if@cftnctoc + \@namedef{listof#2}{% + \@cfttocstart + \if@cfthaschapter + \chapter*{#4} + \else + \section*{#4} + \fi + \@nameuse{cftmark#3} + \@starttoc{#3}% + \@cfttocfinish} + \else + \@namedef{listof#2}{% + \@cfttocstart + \par + \begingroup + \parindent\z@ \parskip\cftparskip + \@nameuse{@cftmake#3title} + \@starttoc{#3}% + \endgroup + \@cfttocfinish} + \fi + + \@namedef{@cftmake#3title}{% + \addpenalty\@secpenalty + \if@cfthaschapter + \vspace*{\@nameuse{cftbefore#3titleskip}} + \else + \vspace{\@nameuse{cftbefore#3titleskip}} + \fi + \@cftpagestyle + {\interlinepenalty\@M + {\@nameuse{cft#3titlefont}#4}{\@nameuse{cftafter#3title}} + \@nameuse{cftmark#3} + \par\nobreak + \vskip \@nameuse{cftafter#3titleskip} + \@afterheading}} + + \expandafter\newlength\csname cftbefore#3titleskip\endcsname + \expandafter\newlength\csname cftafter#3titleskip\endcsname + \if@cfthaschapter + \setlength{\@nameuse{cftbefore#3titleskip}}{50pt} + \setlength{\@nameuse{cftafter#3titleskip}}{40pt} + \if@cftkoma + \@namedef{cft#3titlefont}{\size@chapter\sectfont} + \else + \@namedef{cft#3titlefont}{\normalfont\Huge\bfseries} + \fi + \else + \setlength{\@nameuse{cftbefore#3titleskip}}{3.5ex \@plus 1ex \@minus .2ex} + \setlength{\@nameuse{cftafter#3titleskip}}{2.3ex \@plus .2ex} + \if@cftkoma + \@namedef{cft#3titlefont}{\size@section\sectfont} + \else + \@namedef{cft#3titlefont}{\normalfont\Huge\bfseries} + \fi + \fi + \@namedef{cftafter#3title}{} +} % end \newlistof + +\newcommand{\cftsetindents}[3]{% + \def\@cftemp{#1} + \ifx\@cftemp\cftchapname + \@cftsetindents{chap}{#2}{#3} + \else + \ifx\@cftemp\cftsecname \@cftsetindents{sec}{#2}{#3} + \else + \ifx\@cftemp\cftsubsecname \@cftsetindents{subsec}{#2}{#3} + \else + \ifx\@cftemp\cftsubsubsecname \@cftsetindents{subsubsec}{#2}{#3} + \else + \ifx\@cftemp\cftparaname \@cftsetindents{para}{#2}{#3} + \else + \ifx\@cftemp\cftsubparaname \@cftsetindents{subpara}{#2}{#3} + \else + \ifx\@cftemp\cftfigname \@cftsetindents{fig}{#2}{#3} + \else + \ifx\@cftemp\cftsubfigname \@cftsetindents{subfig}{#2}{#3} + \else + \ifx\@cftemp\cfttabname \@cftsetindents{tab}{#2}{#3} + \else + \ifx\@cftemp\cftsubtabname \@cftsetindents{subtab}{#2}{#3} + \else + \@cftsetindents{#1}{#2}{#3} + \fi + \fi + \fi + \fi + \fi + \fi + \fi + \fi + \fi + \fi +} + +\newcommand{\@cftsetindents}[3]{% + \setlength{\@nameuse{cft#1indent}}{#2} + \setlength{\@nameuse{cft#1numwidth}}{#3} +} + +\newcommand{\@cftpnumoff}[1]{% + \@namedef{cft#1fillnum}##1{% + \cftparfillskip\@nameuse{cft#1afterpnum}\par}} + +\newcommand*{\cftchapname}{chapter} +\newcommand*{\cftsecname}{section} +\newcommand*{\cftsubsecname}{subsection} +\newcommand*{\cftsubsubsecname}{subsubsection} +\newcommand*{\cftparaname}{paragraph} +\newcommand*{\cftsubparaname}{subparagraph} +\newcommand*{\cftfigname}{figure} +\newcommand*{\cftsubfigname}{subfigure} +\newcommand*{\cfttabname}{table} +\newcommand*{\cftsubtabname}{subtable} + +\DeclareRobustCommand{\cftpagenumbersoff}[1]{% + \def\@cftemp{#1} + \ifx\@cftemp\cftchapname + \@cftpnumoff{chap} + \else + \ifx\@cftemp\cftsecname \@cftpnumoff{sec} + \else + \ifx\@cftemp\cftsubsecname \@cftpnumoff{subsec} + \else + \ifx\@cftemp\cftsubsubsecname \@cftpnumoff{subsubsec} + \else + \ifx\@cftemp\cftparaname \@cftpnumoff{para} + \else + \ifx\@cftemp\cftsubparaname \@cftpnumoff{subpara} + \else + \ifx\@cftemp\cftfigname \@cftpnumoff{fig} + \else + \ifx\@cftemp\cftsubfigname \@cftpnumoff{subfig} + \else + \ifx\@cftemp\cfttabname \@cftpnumoff{tab} + \else + \ifx\@cftemp\cftsubtabname \@cftpnumoff{subtab} + \else + \@cftpnumoff{#1} + \fi + \fi + \fi + \fi + \fi + \fi + \fi + \fi + \fi + \fi +} + +\DeclareRobustCommand{\cftpagenumberson}[1]{% + \def\@cftemp{#1} + \ifx\@cftemp\cftchapname + \@cftpnumon{chap} + \else + \ifx\@cftemp\cftsecname \@cftpnumon{sec} + \else + \ifx\@cftemp\cftsubsecname \@cftpnumon{subsec} + \else + \ifx\@cftemp\cftsubsubsecname \@cftpnumon{subsubsec} + \else + \ifx\@cftemp\cftparaname \@cftpnumon{para} + \else + \ifx\@cftemp\cftsubparaname \@cftpnumon{subpara} + \else + \ifx\@cftemp\cftfigname \@cftpnumon{fig} + \else + \ifx\@cftemp\cftsubfigname \@cftpnumon{subfig} + \else + \ifx\@cftemp\cfttabname \@cftpnumon{tab} + \else + \ifx\@cftemp\cftsubtabname \@cftpnumon{subtab} + \else + \@cftpnumon{#1} + \fi + \fi + \fi + \fi + \fi + \fi + \fi + \fi + \fi + \fi +} + +\newcommand{\@cftpnumon}[1]{% + \@namedef{cft#1fillnum}##1{% + {\@nameuse{cft#1leader}}\nobreak + \hb@xt@\@pnumwidth{\hfil\@nameuse{cft#1pagefont}##1}\@nameuse{cft#1afterpnum}\par}} + +\newcommand{\cftchapterprecis}[1]{% + \cftchapterprecishere{#1} + \cftchapterprecistoc{#1}} +\newcommand{\cftchapterprecishere}[1]{% + \vspace*{-2\baselineskip} + \begin{quote}\textit{#1}\end{quote}} +\newcommand{\cftchapterprecistoc}[1]{\addtocontents{toc}{% + {\leftskip \cftchapindent\relax + \advance\leftskip \cftchapnumwidth\relax + \rightskip \@tocrmarg\relax + \textit{#1}\protect\par}}} + +\newcommand{\cftlocalchange}[3]{% + \addtocontents{#1}{\protect\cftsetpnumwidth{#2} \protect\cftsetrmarg{#3}}} +\newcommand{\cftaddtitleline}[4]{\addtocontents{#1}{% + \protect\contentsline{#2}{#3}{#4}}} +\newcommand{\cftaddnumtitleline}[5]{\addtocontents{#1}{% + \protect\contentsline{#2}{\protect\numberline{#3}#4}{#5}}} +\AtBeginDocument{% + \@ifpackageloaded{hyperref}{% + \renewcommand{\cftaddtitleline}[4]{\addtocontents{#1}{% + \protect\contentsline{#2}{#3}{#4}{\@currentHref}}} + \renewcommand{\cftaddnumtitleline}[5]{\addtocontents{#1}{% + \protect\contentsline{#2}{\protect\numberline{#3}#4}{#5}{\@currentHref}}} + }{} +} + +\endinput +%% +%% End of file `tocloft.sty'. diff --git a/resources/latex/warn.pdf b/resources/latex/warn.pdf new file mode 100644 index 00000000..f13902a0 Binary files /dev/null and b/resources/latex/warn.pdf differ diff --git a/version b/version index ad55eb85..0fa4ae48 100644 --- a/version +++ b/version @@ -1 +1 @@ -v3.0.0 +3.3.0 \ No newline at end of file