Skip to content

Commit

Permalink
Improve / fix contest booklet generation. Also fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
veluca93 authored and dp1 committed Oct 18, 2023
1 parent fc6a32f commit af3c572
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 4 deletions.
3 changes: 2 additions & 1 deletion data/statements/cms-contest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,8 @@

\NewEnviron{solution}{
\if@showsolutions
\definecolor{backcolor}{gray}{0.95}
\newpage
\definecolor{backcolor}{gray}{0.9}
\pagecolor{backcolor}

\Solution
Expand Down
1 change: 1 addition & 0 deletions data/statements/locale/english.tex
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@
\def\kw@revision{v}
\def\kw@seconds{seconds}
\def\kw@SampleGrader{Sample Grader}
\def\kw@Solution{Solution}
4 changes: 2 additions & 2 deletions src/tools/booklet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::path::{Path, PathBuf};
use anyhow::{bail, Context, Error};
use clap::Parser;

use task_maker_format::ioi::{make_context_booklets, Booklet, BookletConfig, IOITask};
use task_maker_format::ioi::{make_contest_booklets, Booklet, BookletConfig, IOITask};
use task_maker_format::{find_task, EvaluationConfig};

use crate::context::RuntimeContext;
Expand Down Expand Up @@ -119,7 +119,7 @@ fn get_booklets_from_task_dirs(
tasks.push(task);
}
let booklets =
make_context_booklets(&tasks, eval_config).context("Failed to get booklet data")?;
make_contest_booklets(&tasks, eval_config).context("Failed to get booklet data")?;
let mut task = IOITask::fake();
task.title = "Booklet compilation".into();
task.name = "booklet".into();
Expand Down
14 changes: 14 additions & 0 deletions task-maker-format/src/ioi/statement/booklet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ pub struct BookletConfig {
pub date: Option<String>,
/// The logo of the contest.
pub logo: Option<String>,
/// The path to the intro page.
pub intro_page: Option<PathBuf>,
}

/// Template to use to render the `booklet.tex` file.
Expand All @@ -54,6 +56,7 @@ pub struct BookletTemplate {
logo: String,
packages: String,
tasks: String,
intro_page: String,
}

/// A `Booklet` is a pdf file containing the statements of some tasks. It is compiled from a series
Expand Down Expand Up @@ -81,6 +84,8 @@ pub struct ContestYAML {
pub logo: Option<String>,
/// `Some("True")` if the time and memory limits should be put in the booklet.
pub show_summary: Option<String>,
/// Some(relative_path) for a front page for the booklet.
pub booklet_intro_path: Option<PathBuf>,
/// The list of the tasks in the contest (in the correct order).
pub tasks: Vec<String>,
}
Expand Down Expand Up @@ -224,6 +229,13 @@ impl Booklet {
logo: self.config.logo.clone().unwrap_or_default(),
packages: packages.iter().sorted().join("\n"),
tasks: tasks.join("\n"),
intro_page: self
.config
.intro_page
.clone()
.map(std::fs::read_to_string)
.unwrap_or_else(|| Ok(String::new()))
.unwrap_or_default(),
}
.to_string()
}
Expand Down Expand Up @@ -295,6 +307,7 @@ impl BookletConfig {
location: contest_yaml.location,
date: contest_yaml.date,
logo: contest_yaml.logo,
intro_page: contest_yaml.booklet_intro_path,
})
} else {
Ok(BookletConfig {
Expand All @@ -307,6 +320,7 @@ impl BookletConfig {
location: None,
date: None,
logo: None,
intro_page: None,
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion task-maker-format/src/ioi/statement/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub fn make_task_booklets(
}

/// Find all the `Booklet` it makes sense to build for all the provided tasks.
pub fn make_context_booklets(
pub fn make_contest_booklets(
tasks: &[IOITask],
eval_config: &EvaluationConfig,
) -> Result<Vec<Booklet>, Error> {
Expand Down
1 change: 1 addition & 0 deletions task-maker-format/src/ioi/statement/templates/booklet.tex
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
%{packages}%

\begin{document}
%{intro_page}%
\begin{contest}{%{description}%}{%{location}%}{%{date}%}
\setContestLogo{%{logo}%}
%{tasks}%
Expand Down

0 comments on commit af3c572

Please sign in to comment.