Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for latex #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Added support for latex #17

wants to merge 1 commit into from

Conversation

Ulimo
Copy link

@Ulimo Ulimo commented May 1, 2022

This change adds support latex output. It also adds support to read an algorithm from a textfile.

This PR fixes #15

A suggestion that could improve this is that

\begin{algorithm}
\caption{...}
\begin{algorithmic}
...
\end{algorithmic}
\end{algorithm}

Would be injected in the future so its not required to change the code as in this example.
The directive could then be used like:

.. pcode:: filename.tex
  :caption: Caption text

filename.tex

\Procedure{Quicksort}{$A, p, r$}
\EndProcedure

This also removes some boilerplate code when designing an algorithm.

@Ulimo
Copy link
Author

Ulimo commented May 4, 2022

@xxks-kkk is there anything missing to get this merged in?

@xxks-kkk
Copy link
Owner

xxks-kkk commented May 4, 2022 via email

@xxks-kkk
Copy link
Owner

xxks-kkk commented May 9, 2022

@Ulimo Can you please update the demo doc to showcase everything works properly? I tried to verify your PR but hit some issues.

In specific, I add the following to conf.py

# -- Options for LaTeX output ---------------------------------------------

latex_elements = {
    # The paper size ('letterpaper' or 'a4paper').
    #
    # 'papersize': 'letterpaper',

    # The font size ('10pt', '11pt' or '12pt').
    #
    # 'pointsize': '10pt',

    # Additional stuff for the LaTeX preamble.
    #
    # 'preamble': '',

    # Latex figure (float) alignment
    #
    # 'figure_align': 'htbp',
}

# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
#  author, documentclass [howto, manual, or own class]).
latex_documents = [
    (master_doc, 'sphinxcontrib-pseudocode.tex', 'sphinxcontrib-pseudocode documentation',
     'Zeyuan Hu', 'manual'),
]

and is able to generate the necessary TeX files with the command from docs/ directory

sphinx-build -b latex . _build/latex -T -a -E

After I run make all-pdf from the _build/latex, I hit the following error:

<--- snipped --->
LaTeX Warning: Hyper reference `index:quick-sort' on page 1 undefined on input 
line 94.


LaTeX Warning: Reference `index:quick-sort' on page 1 undefined on input line 9
4.


LaTeX Warning: Hyper reference `index:quick-sort' on page 1 undefined on input 
line 98.


LaTeX Warning: Reference `index:quick-sort' on page 1 undefined on input line 9
8.


LaTeX Warning: Hyper reference `index:test-control-blocks' on page 1 undefined 
on input line 102.


LaTeX Warning: Command \LaTeX invalid in math mode on input line 108.


LaTeX Warning: Command \TeX invalid in math mode on input line 108.

! You can't use `\spacefactor' in math mode.
\@->\spacefactor 
                 \@m {}
l.108 ...} directive contains exactly one \(\LaTeX
                                                  \) algorithmic block:
? 

I'm not sure if this is due to my local setup issue (I don't work with building LaTeX from sphinx-doc).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How does this work with make Latex?
3 participants