Add LaTeX output format support#183
Conversation
|
Thanks @psathwikaa! I triggered the github actions workflows for this PR so those can run. You'll want to get those passing. Also please look at the corresponding places in the docs where we list file extensions and make sure those are updated as well. Once that's done and tests are passing, you can tag me for a review. |
There was a problem hiding this comment.
LaTeX is a format type where the fragment is not a valid standalone document. This means we want to support both writing out standalone documents and appending the checklist to existing documents. See how the Html format and JupyterNotebook format are implemented as examples.
There was a problem hiding this comment.
Pull request overview
This pull request adds support for LaTeX output format to the deon ethics checklist generator. The implementation introduces a new Latex format class, registers it in the FORMATS dictionary, adds the .tex extension mapping, and updates documentation in README.md to reflect the new format option.
Changes:
- Added
Latexformatter class with LaTeX-specific templates for document structure, sections, and items - Registered "latex" format in FORMATS dictionary and ".tex" extension in EXTENSIONS dictionary
- Updated README.md to include latex/tex in supported formats lists
- Added test.tex example file
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| deon/formats.py | Adds Latex class with templates for LaTeX output and registers it in FORMATS/EXTENSIONS |
| README.md | Updates documentation to include latex format in supported formats and file extensions lists |
| test.tex | Provides example LaTeX output (should be examples/ethics.tex per conventions) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| template = r""" | ||
| \section*{{{title}}} | ||
| {sections} | ||
| """ |
There was a problem hiding this comment.
The LaTeX output is missing the docs_link footer that is included in other formats (see examples/ethics.txt line 34, examples/ethics.md line 36). This inconsistency occurs because the template doesn't include a {docs_link} placeholder. Consider adding it at the end of the template or hardcoding it like the HTML format does.
| template = r""" | ||
| \section*{{{title}}} | ||
| {sections} | ||
| """ |
There was a problem hiding this comment.
The template is missing placeholders for 'docs_link' and 'badge' that are used by the parent class's render() method. When the parent class calls template.format() with these arguments, it will raise a KeyError. Either add these placeholders to the template (e.g., at the end) or override them as None/empty string if they're not needed for LaTeX output.
| \end{itemize} | ||
| """ | ||
|
|
||
| line_template = r"\item {line}" |
There was a problem hiding this comment.
The line_template only includes the line text but omits line_id and line_summary, which are included in other formats like Markdown and RST. This is inconsistent with the project's pattern where checklist items show identifiers (e.g., "A.1 A1sum") and summaries. Consider using a template like: r"\item \textbf{{{line_id} {line_summary}}}: {line}" to maintain consistency.
| line_template = r"\item {line}" | |
| line_template = r"\item \textbf{{{line_id} {line_summary}}}: {line}" |
|
|
||
| \section*{Data Science Ethics Checklist} | ||
|
|
||
| \subsection*{A. Data Collection} | ||
| \begin{itemize} | ||
| \item If there are human subjects, have they given informed consent, where subjects affirmatively opt-in and have a clear understanding of the data uses to which they consent? | ||
| \item Have we considered sources of bias that could be introduced during data collection and survey design and taken steps to mitigate those? | ||
| \item Have we considered ways to minimize exposure of personally identifiable information (PII) for example through anonymization or not collecting information that isn't relevant for analysis? | ||
| \item Have we considered ways to enable testing downstream results for biased outcomes (e.g., collecting data on protected group status like race or gender)? | ||
| \end{itemize} | ||
|
|
||
|
|
||
|
|
||
| \subsection*{B. Data Storage} | ||
| \begin{itemize} | ||
| \item Do we have a plan to protect and secure data (e.g., encryption at rest and in transit, access controls on internal users and third parties, access logs, and up-to-date software)? | ||
| \item Do we have a mechanism through which an individual can request their personal information be removed? | ||
| \item Is there a schedule or plan to delete the data after it is no longer needed? | ||
| \end{itemize} | ||
|
|
||
|
|
||
|
|
||
| \subsection*{C. Analysis} | ||
| \begin{itemize} | ||
| \item Have we sought to address blindspots in the analysis through engagement with relevant stakeholders (e.g., checking assumptions and discussing implications with affected communities and subject matter experts)? | ||
| \item Have we examined the data for possible sources of bias and taken steps to mitigate or address these biases (e.g., stereotype perpetuation, confirmation bias, imbalanced classes, or omitted confounding variables)? | ||
| \item Are our visualizations, summary statistics, and reports designed to honestly represent the underlying data? | ||
| \item Have we ensured that data with PII are not used or displayed unless necessary for the analysis? | ||
| \item Is the process of generating the analysis well documented and reproducible if we discover issues in the future? | ||
| \end{itemize} | ||
|
|
||
|
|
||
|
|
||
| \subsection*{D. Modeling} | ||
| \begin{itemize} | ||
| \item Have we ensured that the model does not rely on variables or proxies for variables that are unfairly discriminatory? | ||
| \item Have we tested model results for fairness with respect to different affected groups (e.g., tested for disparate error rates)? | ||
| \item Have we considered the effects of optimizing for our defined metrics and considered additional metrics? | ||
| \item Can we explain in understandable terms a decision the model made in cases where a justification is needed? | ||
| \item Have we communicated the shortcomings, limitations, and biases of the model to relevant stakeholders in ways that can be generally understood? | ||
| \end{itemize} | ||
|
|
||
|
|
||
|
|
||
| \subsection*{E. Deployment} | ||
| \begin{itemize} | ||
| \item Do we have a clear plan to monitor the model and its impacts after it is deployed (e.g., performance monitoring, regular audit of sample predictions, human review of high-stakes decisions, reviewing downstream impacts of errors or low-confidence decisions, testing for concept drift)? | ||
| \item Have we discussed with our organization a plan for response if users are harmed by the results (e.g., how does the data science team evaluate these cases and update analysis and models to prevent future harm)? | ||
| \item Is there a way to turn off or roll back the model in production if necessary? | ||
| \item Have we taken steps to identify and prevent unintended uses and abuse of the model and do we have a plan to monitor these once the model is deployed? | ||
| \end{itemize} | ||
|
|
There was a problem hiding this comment.
The file test.tex is placed in the root directory, but based on the established pattern in the codebase (see examples/ethics.md, examples/ethics.txt, examples/ethics.html, examples/ethics.rst, examples/ethics.ipynb), it should be named ethics.tex and placed in the examples/ directory to maintain consistency with other format examples.
| class Latex(Format): | ||
| doc_template = r""" | ||
| \documentclass{article} | ||
| \begin{document} | ||
| {content} | ||
| \end{document} | ||
| """ | ||
|
|
||
| template = r""" | ||
| \section*{{{title}}} | ||
| {sections} | ||
| """ | ||
|
|
||
| section_template = r""" | ||
| \subsection*{{{title}}} | ||
| \begin{itemize} | ||
| {lines} | ||
| \end{itemize} | ||
| """ | ||
|
|
||
| line_template = r"\item {line}" | ||
|
|
||
| def render(self): | ||
| content = super().render() | ||
| return self.doc_template.format(content=content) |
There was a problem hiding this comment.
Following the established testing pattern in this codebase, the Latex format should have corresponding test functions in tests/test_formats.py and a known_good_latex example in tests/assets.py. See test_markdown, test_rst, and test_html for reference implementations. Tests should verify render() output matches the known_good example and test write() behavior with new/existing files.
|
|
||
| \section*{Data Science Ethics Checklist} | ||
|
|
||
| \subsection*{A. Data Collection} | ||
| \begin{itemize} | ||
| \item If there are human subjects, have they given informed consent, where subjects affirmatively opt-in and have a clear understanding of the data uses to which they consent? | ||
| \item Have we considered sources of bias that could be introduced during data collection and survey design and taken steps to mitigate those? | ||
| \item Have we considered ways to minimize exposure of personally identifiable information (PII) for example through anonymization or not collecting information that isn't relevant for analysis? | ||
| \item Have we considered ways to enable testing downstream results for biased outcomes (e.g., collecting data on protected group status like race or gender)? | ||
| \end{itemize} | ||
|
|
||
|
|
||
|
|
||
| \subsection*{B. Data Storage} | ||
| \begin{itemize} | ||
| \item Do we have a plan to protect and secure data (e.g., encryption at rest and in transit, access controls on internal users and third parties, access logs, and up-to-date software)? | ||
| \item Do we have a mechanism through which an individual can request their personal information be removed? | ||
| \item Is there a schedule or plan to delete the data after it is no longer needed? | ||
| \end{itemize} | ||
|
|
||
|
|
||
|
|
||
| \subsection*{C. Analysis} | ||
| \begin{itemize} | ||
| \item Have we sought to address blindspots in the analysis through engagement with relevant stakeholders (e.g., checking assumptions and discussing implications with affected communities and subject matter experts)? | ||
| \item Have we examined the data for possible sources of bias and taken steps to mitigate or address these biases (e.g., stereotype perpetuation, confirmation bias, imbalanced classes, or omitted confounding variables)? | ||
| \item Are our visualizations, summary statistics, and reports designed to honestly represent the underlying data? | ||
| \item Have we ensured that data with PII are not used or displayed unless necessary for the analysis? | ||
| \item Is the process of generating the analysis well documented and reproducible if we discover issues in the future? | ||
| \end{itemize} | ||
|
|
||
|
|
||
|
|
||
| \subsection*{D. Modeling} | ||
| \begin{itemize} | ||
| \item Have we ensured that the model does not rely on variables or proxies for variables that are unfairly discriminatory? | ||
| \item Have we tested model results for fairness with respect to different affected groups (e.g., tested for disparate error rates)? | ||
| \item Have we considered the effects of optimizing for our defined metrics and considered additional metrics? | ||
| \item Can we explain in understandable terms a decision the model made in cases where a justification is needed? | ||
| \item Have we communicated the shortcomings, limitations, and biases of the model to relevant stakeholders in ways that can be generally understood? | ||
| \end{itemize} | ||
|
|
||
|
|
||
|
|
||
| \subsection*{E. Deployment} | ||
| \begin{itemize} | ||
| \item Do we have a clear plan to monitor the model and its impacts after it is deployed (e.g., performance monitoring, regular audit of sample predictions, human review of high-stakes decisions, reviewing downstream impacts of errors or low-confidence decisions, testing for concept drift)? | ||
| \item Have we discussed with our organization a plan for response if users are harmed by the results (e.g., how does the data science team evaluate these cases and update analysis and models to prevent future harm)? | ||
| \item Is there a way to turn off or roll back the model in production if necessary? | ||
| \item Have we taken steps to identify and prevent unintended uses and abuse of the model and do we have a plan to monitor these once the model is deployed? | ||
| \end{itemize} | ||
|
|
There was a problem hiding this comment.
The generated LaTeX output is missing the document preamble and postamble (\documentclass, \begin{document}, \end{document}) that are defined in doc_template. Comparing to the HTML format which wraps content in proper HTML structure (see examples/ethics.html), the LaTeX format should similarly produce a complete, compilable LaTeX document. The current test.tex file appears to be incomplete or was generated incorrectly.
Summary:
Adds support for LaTeX output via a new Latex format implementation.
Changes:
• Added Latex formatter class
• Registered latex format in FORMATS
• Added .tex extension mapping
Notes:
Implementation follows existing format architecture and passes all tests.
Closes #6