Text Formattinghow to align in flexible pseudocode?

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
migdalskiy
Posts: 4
Joined: Sun Sep 27, 2009 1:40 am

how to align in flexible pseudocode?

Post by migdalskiy »

Hi,

I'm using listings package (http://ctan.org/pkg/listings) to show pseudocode, and want to add comments to the right side of my listing, where there's a lot of white space now.

I need to use flexible column width (it seems to work better). I set language=TeX. I need comments left-justified, but the whole block of comments to be on the right side (so the box enclosing all comments should be right-justified).

If I make columns fixed, I can usually align comments with spaces, but fixed doesn't look good and I figured there must be less hacky solution to this.

Here's what my listing looks like now:

Code: Select all

\lstset{language=TeX,emph={foreach},emphstyle=\emph,morecomment=[l][\tiny]{//},commentstyle=\itshape,columns=flexible}
\begin{lstlisting}[float,caption={Basic SAT Algorithm.},label=Migdalskiy-BruteForceSATMTD, numbers=right, stepnumber=1,mathescape=true,columns=flexible,lineskip=2pt,basicstyle=\small,keywords={for,each,do,and,or,if,then,return,procedure,function}]
$(\vec s_{min},d_{min}) \leftarrow (\vec 0, -\infty)$
 for each $face_A \in F(A)$ do
	checkDirection( $-\vec n( face_A )$ )
 for each $face_B \in F(B)$ do                              
	checkDirection( $\vec n( face_B )$ )
... blah , blah , blah ...
 function support($Shape$, $\vec s$)
	return $min\{\vec s \cdot \vec v : \forall \vec v \in V(Shape)\}$
\end{lstlisting}

I'm a newbie and can't find it anywhere in listings documentation.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX books
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Re: how to align in flexible pseudocode?

Post by gmedina »

Hi,

I don't fully understand your intention. Can you please post an example (or a link to a page where we can see an example) of what exactly you desire to achieve?
1,1,2,3,5,8,13,21,34,55,89,144,233,...
migdalskiy
Posts: 4
Joined: Sun Sep 27, 2009 1:40 am

how to align in flexible pseudocode?

Post by migdalskiy »

Hello:

Here is what I'm trying to do: I want to insert comments like those inside the pink box: left-justified, with the box being right-justified. I also posted it in my blog: http://blog.godflame.com/?p=73
CommentsPost-300x127.png
CommentsPost-300x127.png (37.49 KiB) Viewed 6671 times
CommentsPost-966x412.png
CommentsPost-966x412.png (45.72 KiB) Viewed 6671 times
Thank you,
Sergiy
migdalskiy
Posts: 4
Joined: Sun Sep 27, 2009 1:40 am

Re: how to align in flexible pseudocode?

Post by migdalskiy »

It appears there are at least two ways to do that. Not awfully convenient, but functional

1. Tab characters seem to work even in flexible columns.

2. escapechar=\% in options will turn on escape to LaTeX. Then, using %\mbox[2in][r]{comment}% kinda works, too.
Post Reply