Format Code/PseudocodePut a grey background behind code extracts in a Latex document (like this site does)Pseudocode, special formattingAddition and subtraction of chemical equationsReplicate pseudocode formatPseudocode in LaTeXHow to format a pseudocode algorithmFormatting in Latex - PseudocodeHow to write pseudocode similar to code presented in “Beautiful Code” by J. R. HeardPseudocode vertical linesChange name in pseudocodeLatex formatting a pseudocode

CLI: Get information Ubuntu releases

Why are there no stars visible in cislunar space?

"Marked down as someone wanting to sell shares." What does that mean?

The English Debate

Homology of the fiber

What is it called when someone votes for an option that's not their first choice?

Why is "la Gestapo" feminine?

Nested Dynamic SOQL Query

Help with identifying unique aircraft over NE Pennsylvania

How do you justify more code being written by following clean code practices?

label a part of commutative diagram

Exit shell with shortcut (not typing exit) that closes session properly

Should a narrator ever describe things based on a characters view instead of fact?

Print last inputted byte

How to balance a monster modification (zombie)?

UK Tourist Visa- Enquiry

How to find the largest number(s) in a list of elements, possibly non-unique?

is this saw blade faulty?

Air travel with refrigerated insulin

Asserting that Atheism and Theism are both faith based positions

Is xar preinstalled on macOS?

Could any one tell what PN is this Chip? Thanks~

Hackerrank All Women's Codesprint 2019: Name the Product

TDE Master Key Rotation



Format Code/Pseudocode


Put a grey background behind code extracts in a Latex document (like this site does)Pseudocode, special formattingAddition and subtraction of chemical equationsReplicate pseudocode formatPseudocode in LaTeXHow to format a pseudocode algorithmFormatting in Latex - PseudocodeHow to write pseudocode similar to code presented in “Beautiful Code” by J. R. HeardPseudocode vertical linesChange name in pseudocodeLatex formatting a pseudocode













0















In a document containing a lot of other stuff, I have the following code which I have kept in verbatim(for lack of other ideas). As you can see, the alignment doesn't look so good.Image

How do I make it more presentable, so that it becomes more readable, with indentation perhaps(verbatim doesnt seem to handle spaces and tabs)?



documentclass[]article 
begindocument
beginverbatim

if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];


endverbatim
enddocument









share|improve this question
























  • A tip: If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "" on it).

    – DG'
    Feb 26 at 12:01











  • @DG' Is it more readable now? I wanna know how I could present it in a Latex Document, not on tex.stackexchange.

    – GermanShepherd
    Feb 26 at 12:13












  • Do you want LaTeX to indent it for you? It isn't the right tool for the job. There are editors out there that will support the programming language and will have auto-indentation for it, so why not using one of those?

    – TeXnician
    Feb 26 at 12:13






  • 1





    Well what I see in your screenshot is some verbatim code which you claim that one would see to be badly aligned. I do not get which kind of more readability you want. Making it stand out from ordinary text (maybe listings would help here) or making it nice in itself (external code formatting might be the way to go). Also your claim that verbatim can't handle spaces or tabs is wrong.

    – TeXnician
    Feb 26 at 12:23






  • 2





    For the automatic indenting you need to call an external tool, as neither listings or minted provides such functionality as far as I know. This can be done from within LaTeX with a (medium) bit of trouble. Which operating system do you use?

    – Marijn
    Feb 26 at 12:51















0















In a document containing a lot of other stuff, I have the following code which I have kept in verbatim(for lack of other ideas). As you can see, the alignment doesn't look so good.Image

How do I make it more presentable, so that it becomes more readable, with indentation perhaps(verbatim doesnt seem to handle spaces and tabs)?



documentclass[]article 
begindocument
beginverbatim

if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];


endverbatim
enddocument









share|improve this question
























  • A tip: If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "" on it).

    – DG'
    Feb 26 at 12:01











  • @DG' Is it more readable now? I wanna know how I could present it in a Latex Document, not on tex.stackexchange.

    – GermanShepherd
    Feb 26 at 12:13












  • Do you want LaTeX to indent it for you? It isn't the right tool for the job. There are editors out there that will support the programming language and will have auto-indentation for it, so why not using one of those?

    – TeXnician
    Feb 26 at 12:13






  • 1





    Well what I see in your screenshot is some verbatim code which you claim that one would see to be badly aligned. I do not get which kind of more readability you want. Making it stand out from ordinary text (maybe listings would help here) or making it nice in itself (external code formatting might be the way to go). Also your claim that verbatim can't handle spaces or tabs is wrong.

    – TeXnician
    Feb 26 at 12:23






  • 2





    For the automatic indenting you need to call an external tool, as neither listings or minted provides such functionality as far as I know. This can be done from within LaTeX with a (medium) bit of trouble. Which operating system do you use?

    – Marijn
    Feb 26 at 12:51













0












0








0


2






In a document containing a lot of other stuff, I have the following code which I have kept in verbatim(for lack of other ideas). As you can see, the alignment doesn't look so good.Image

How do I make it more presentable, so that it becomes more readable, with indentation perhaps(verbatim doesnt seem to handle spaces and tabs)?



documentclass[]article 
begindocument
beginverbatim

if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];


endverbatim
enddocument









share|improve this question
















In a document containing a lot of other stuff, I have the following code which I have kept in verbatim(for lack of other ideas). As you can see, the alignment doesn't look so good.Image

How do I make it more presentable, so that it becomes more readable, with indentation perhaps(verbatim doesnt seem to handle spaces and tabs)?



documentclass[]article 
begindocument
beginverbatim

if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];


endverbatim
enddocument






formatting pseudocode






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 5 mins ago







GermanShepherd

















asked Feb 26 at 11:58









GermanShepherdGermanShepherd

545220




545220












  • A tip: If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "" on it).

    – DG'
    Feb 26 at 12:01











  • @DG' Is it more readable now? I wanna know how I could present it in a Latex Document, not on tex.stackexchange.

    – GermanShepherd
    Feb 26 at 12:13












  • Do you want LaTeX to indent it for you? It isn't the right tool for the job. There are editors out there that will support the programming language and will have auto-indentation for it, so why not using one of those?

    – TeXnician
    Feb 26 at 12:13






  • 1





    Well what I see in your screenshot is some verbatim code which you claim that one would see to be badly aligned. I do not get which kind of more readability you want. Making it stand out from ordinary text (maybe listings would help here) or making it nice in itself (external code formatting might be the way to go). Also your claim that verbatim can't handle spaces or tabs is wrong.

    – TeXnician
    Feb 26 at 12:23






  • 2





    For the automatic indenting you need to call an external tool, as neither listings or minted provides such functionality as far as I know. This can be done from within LaTeX with a (medium) bit of trouble. Which operating system do you use?

    – Marijn
    Feb 26 at 12:51

















  • A tip: If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "" on it).

    – DG'
    Feb 26 at 12:01











  • @DG' Is it more readable now? I wanna know how I could present it in a Latex Document, not on tex.stackexchange.

    – GermanShepherd
    Feb 26 at 12:13












  • Do you want LaTeX to indent it for you? It isn't the right tool for the job. There are editors out there that will support the programming language and will have auto-indentation for it, so why not using one of those?

    – TeXnician
    Feb 26 at 12:13






  • 1





    Well what I see in your screenshot is some verbatim code which you claim that one would see to be badly aligned. I do not get which kind of more readability you want. Making it stand out from ordinary text (maybe listings would help here) or making it nice in itself (external code formatting might be the way to go). Also your claim that verbatim can't handle spaces or tabs is wrong.

    – TeXnician
    Feb 26 at 12:23






  • 2





    For the automatic indenting you need to call an external tool, as neither listings or minted provides such functionality as far as I know. This can be done from within LaTeX with a (medium) bit of trouble. Which operating system do you use?

    – Marijn
    Feb 26 at 12:51
















A tip: If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "" on it).

– DG'
Feb 26 at 12:01





A tip: If you indent lines by 4 spaces, they'll be marked as a code sample. You can also highlight the code and click the "code" button (with "" on it).

– DG'
Feb 26 at 12:01













@DG' Is it more readable now? I wanna know how I could present it in a Latex Document, not on tex.stackexchange.

– GermanShepherd
Feb 26 at 12:13






@DG' Is it more readable now? I wanna know how I could present it in a Latex Document, not on tex.stackexchange.

– GermanShepherd
Feb 26 at 12:13














Do you want LaTeX to indent it for you? It isn't the right tool for the job. There are editors out there that will support the programming language and will have auto-indentation for it, so why not using one of those?

– TeXnician
Feb 26 at 12:13





Do you want LaTeX to indent it for you? It isn't the right tool for the job. There are editors out there that will support the programming language and will have auto-indentation for it, so why not using one of those?

– TeXnician
Feb 26 at 12:13




1




1





Well what I see in your screenshot is some verbatim code which you claim that one would see to be badly aligned. I do not get which kind of more readability you want. Making it stand out from ordinary text (maybe listings would help here) or making it nice in itself (external code formatting might be the way to go). Also your claim that verbatim can't handle spaces or tabs is wrong.

– TeXnician
Feb 26 at 12:23





Well what I see in your screenshot is some verbatim code which you claim that one would see to be badly aligned. I do not get which kind of more readability you want. Making it stand out from ordinary text (maybe listings would help here) or making it nice in itself (external code formatting might be the way to go). Also your claim that verbatim can't handle spaces or tabs is wrong.

– TeXnician
Feb 26 at 12:23




2




2





For the automatic indenting you need to call an external tool, as neither listings or minted provides such functionality as far as I know. This can be done from within LaTeX with a (medium) bit of trouble. Which operating system do you use?

– Marijn
Feb 26 at 12:51





For the automatic indenting you need to call an external tool, as neither listings or minted provides such functionality as far as I know. This can be done from within LaTeX with a (medium) bit of trouble. Which operating system do you use?

– Marijn
Feb 26 at 12:51










3 Answers
3






active

oldest

votes


















5














Something like this?



documentclassbook
usepackagelistings

lstdefinestylemyListingStyle

basicstyle = smallttfamily,
breaklines = true,


begindocument

beginlstlisting[
style = myListingStyle,
caption = Nice listing.
]
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endlstlisting

enddocument


enter image description here



See Put a grey background behind code extracts in a Latex document (like this site does) for example for adding a background color. It's also possible to load the code from an external file -- just have a look at related questions.






share|improve this answer

























  • Is it possible to remove the caption for listings?

    – GermanShepherd
    Feb 26 at 12:35











  • @GermanShepherd Yes, just have a look at the code and remove caption = Nice listing..

    – Dr. Manuel Kuehner
    Feb 26 at 12:36


















9














Verbatim



Contrary to what you claim in your question, verbatim supports spaces and indentation, so why not use it?



verbatim



documentclass[]article 
begindocument
beginverbatim
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endverbatim
enddocument


Listings



The listings package can add colors.



listings



documentclass[]article
usepackagelistings
usepackagexcolor
lstsetbasicstyle=ttfamily,language=c,keywordstyle=colorblue
begindocument
beginlstlisting
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endlstlisting
enddocument


Minted



The minted package is even more powerful…



minted



% arara: pdflatex: shell: yes
documentclass[]article
usepackageminted
begindocument
beginmintedc
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endminted
enddocument


Tcblisting



You can of course combine it with tcolorbox or something else…



tcblisting



% arara: pdflatex: shell: yes
documentclass[]article
usepackageminted
usepackage[minted]tcolorbox
newtcblistingmylistinglisting only,listing engine=minted, minted language=c,colback=gray!20
begindocument
beginmylisting
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endmylisting
enddocument





share|improve this answer




















  • 1





    +1: Very complete answer :)

    – Dr. Manuel Kuehner
    Feb 26 at 12:36






  • 2





    @Dr.ManuelKuehner By far not, but listing some common options :)

    – TeXnician
    Feb 26 at 12:37


















1














As already stated by others, verbatim does work for code (I use it for that purpose). The issue you see is that you usually format your code with tabs which verbatim is ignoring for some reason. So what I do is I put my code into verbatim select it and replace tabs with say 4 (or any number for that matter) of spaces (but just inside the selection).






share|improve this answer

























  • Are you sure that verbatim does not support tabs? In my case, it does.

    – JouleV
    Feb 26 at 16:16











  • i wrote a 80page script About the use of a finite element Analysis program that included a LOT of example Code with tabs. and i had to replace them all because else my Output would look like the one that the OP shared. this may depend on the tex Distribution however.

    – der bender
    Feb 26 at 16:18










Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "85"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f476745%2fformat-code-pseudocode%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes









5














Something like this?



documentclassbook
usepackagelistings

lstdefinestylemyListingStyle

basicstyle = smallttfamily,
breaklines = true,


begindocument

beginlstlisting[
style = myListingStyle,
caption = Nice listing.
]
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endlstlisting

enddocument


enter image description here



See Put a grey background behind code extracts in a Latex document (like this site does) for example for adding a background color. It's also possible to load the code from an external file -- just have a look at related questions.






share|improve this answer

























  • Is it possible to remove the caption for listings?

    – GermanShepherd
    Feb 26 at 12:35











  • @GermanShepherd Yes, just have a look at the code and remove caption = Nice listing..

    – Dr. Manuel Kuehner
    Feb 26 at 12:36















5














Something like this?



documentclassbook
usepackagelistings

lstdefinestylemyListingStyle

basicstyle = smallttfamily,
breaklines = true,


begindocument

beginlstlisting[
style = myListingStyle,
caption = Nice listing.
]
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endlstlisting

enddocument


enter image description here



See Put a grey background behind code extracts in a Latex document (like this site does) for example for adding a background color. It's also possible to load the code from an external file -- just have a look at related questions.






share|improve this answer

























  • Is it possible to remove the caption for listings?

    – GermanShepherd
    Feb 26 at 12:35











  • @GermanShepherd Yes, just have a look at the code and remove caption = Nice listing..

    – Dr. Manuel Kuehner
    Feb 26 at 12:36













5












5








5







Something like this?



documentclassbook
usepackagelistings

lstdefinestylemyListingStyle

basicstyle = smallttfamily,
breaklines = true,


begindocument

beginlstlisting[
style = myListingStyle,
caption = Nice listing.
]
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endlstlisting

enddocument


enter image description here



See Put a grey background behind code extracts in a Latex document (like this site does) for example for adding a background color. It's also possible to load the code from an external file -- just have a look at related questions.






share|improve this answer















Something like this?



documentclassbook
usepackagelistings

lstdefinestylemyListingStyle

basicstyle = smallttfamily,
breaklines = true,


begindocument

beginlstlisting[
style = myListingStyle,
caption = Nice listing.
]
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endlstlisting

enddocument


enter image description here



See Put a grey background behind code extracts in a Latex document (like this site does) for example for adding a background color. It's also possible to load the code from an external file -- just have a look at related questions.







share|improve this answer














share|improve this answer



share|improve this answer








edited Feb 26 at 12:46

























answered Feb 26 at 12:28









Dr. Manuel KuehnerDr. Manuel Kuehner

9,25932769




9,25932769












  • Is it possible to remove the caption for listings?

    – GermanShepherd
    Feb 26 at 12:35











  • @GermanShepherd Yes, just have a look at the code and remove caption = Nice listing..

    – Dr. Manuel Kuehner
    Feb 26 at 12:36

















  • Is it possible to remove the caption for listings?

    – GermanShepherd
    Feb 26 at 12:35











  • @GermanShepherd Yes, just have a look at the code and remove caption = Nice listing..

    – Dr. Manuel Kuehner
    Feb 26 at 12:36
















Is it possible to remove the caption for listings?

– GermanShepherd
Feb 26 at 12:35





Is it possible to remove the caption for listings?

– GermanShepherd
Feb 26 at 12:35













@GermanShepherd Yes, just have a look at the code and remove caption = Nice listing..

– Dr. Manuel Kuehner
Feb 26 at 12:36





@GermanShepherd Yes, just have a look at the code and remove caption = Nice listing..

– Dr. Manuel Kuehner
Feb 26 at 12:36











9














Verbatim



Contrary to what you claim in your question, verbatim supports spaces and indentation, so why not use it?



verbatim



documentclass[]article 
begindocument
beginverbatim
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endverbatim
enddocument


Listings



The listings package can add colors.



listings



documentclass[]article
usepackagelistings
usepackagexcolor
lstsetbasicstyle=ttfamily,language=c,keywordstyle=colorblue
begindocument
beginlstlisting
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endlstlisting
enddocument


Minted



The minted package is even more powerful…



minted



% arara: pdflatex: shell: yes
documentclass[]article
usepackageminted
begindocument
beginmintedc
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endminted
enddocument


Tcblisting



You can of course combine it with tcolorbox or something else…



tcblisting



% arara: pdflatex: shell: yes
documentclass[]article
usepackageminted
usepackage[minted]tcolorbox
newtcblistingmylistinglisting only,listing engine=minted, minted language=c,colback=gray!20
begindocument
beginmylisting
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endmylisting
enddocument





share|improve this answer




















  • 1





    +1: Very complete answer :)

    – Dr. Manuel Kuehner
    Feb 26 at 12:36






  • 2





    @Dr.ManuelKuehner By far not, but listing some common options :)

    – TeXnician
    Feb 26 at 12:37















9














Verbatim



Contrary to what you claim in your question, verbatim supports spaces and indentation, so why not use it?



verbatim



documentclass[]article 
begindocument
beginverbatim
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endverbatim
enddocument


Listings



The listings package can add colors.



listings



documentclass[]article
usepackagelistings
usepackagexcolor
lstsetbasicstyle=ttfamily,language=c,keywordstyle=colorblue
begindocument
beginlstlisting
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endlstlisting
enddocument


Minted



The minted package is even more powerful…



minted



% arara: pdflatex: shell: yes
documentclass[]article
usepackageminted
begindocument
beginmintedc
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endminted
enddocument


Tcblisting



You can of course combine it with tcolorbox or something else…



tcblisting



% arara: pdflatex: shell: yes
documentclass[]article
usepackageminted
usepackage[minted]tcolorbox
newtcblistingmylistinglisting only,listing engine=minted, minted language=c,colback=gray!20
begindocument
beginmylisting
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endmylisting
enddocument





share|improve this answer




















  • 1





    +1: Very complete answer :)

    – Dr. Manuel Kuehner
    Feb 26 at 12:36






  • 2





    @Dr.ManuelKuehner By far not, but listing some common options :)

    – TeXnician
    Feb 26 at 12:37













9












9








9







Verbatim



Contrary to what you claim in your question, verbatim supports spaces and indentation, so why not use it?



verbatim



documentclass[]article 
begindocument
beginverbatim
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endverbatim
enddocument


Listings



The listings package can add colors.



listings



documentclass[]article
usepackagelistings
usepackagexcolor
lstsetbasicstyle=ttfamily,language=c,keywordstyle=colorblue
begindocument
beginlstlisting
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endlstlisting
enddocument


Minted



The minted package is even more powerful…



minted



% arara: pdflatex: shell: yes
documentclass[]article
usepackageminted
begindocument
beginmintedc
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endminted
enddocument


Tcblisting



You can of course combine it with tcolorbox or something else…



tcblisting



% arara: pdflatex: shell: yes
documentclass[]article
usepackageminted
usepackage[minted]tcolorbox
newtcblistingmylistinglisting only,listing engine=minted, minted language=c,colback=gray!20
begindocument
beginmylisting
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endmylisting
enddocument





share|improve this answer















Verbatim



Contrary to what you claim in your question, verbatim supports spaces and indentation, so why not use it?



verbatim



documentclass[]article 
begindocument
beginverbatim
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endverbatim
enddocument


Listings



The listings package can add colors.



listings



documentclass[]article
usepackagelistings
usepackagexcolor
lstsetbasicstyle=ttfamily,language=c,keywordstyle=colorblue
begindocument
beginlstlisting
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endlstlisting
enddocument


Minted



The minted package is even more powerful…



minted



% arara: pdflatex: shell: yes
documentclass[]article
usepackageminted
begindocument
beginmintedc
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endminted
enddocument


Tcblisting



You can of course combine it with tcolorbox or something else…



tcblisting



% arara: pdflatex: shell: yes
documentclass[]article
usepackageminted
usepackage[minted]tcolorbox
newtcblistingmylistinglisting only,listing engine=minted, minted language=c,colback=gray!20
begindocument
beginmylisting
if (n == 0 || n == 1)
return n;

j = 0;
for (i = 0; i < n-1; i++)
if (arr[i] != arr[i+1])
arr[j] = arr[i];
j++;


arr[j++] = arr[n-1];
endmylisting
enddocument






share|improve this answer














share|improve this answer



share|improve this answer








edited Feb 26 at 12:36

























answered Feb 26 at 12:29









TeXnicianTeXnician

25.7k63390




25.7k63390







  • 1





    +1: Very complete answer :)

    – Dr. Manuel Kuehner
    Feb 26 at 12:36






  • 2





    @Dr.ManuelKuehner By far not, but listing some common options :)

    – TeXnician
    Feb 26 at 12:37












  • 1





    +1: Very complete answer :)

    – Dr. Manuel Kuehner
    Feb 26 at 12:36






  • 2





    @Dr.ManuelKuehner By far not, but listing some common options :)

    – TeXnician
    Feb 26 at 12:37







1




1





+1: Very complete answer :)

– Dr. Manuel Kuehner
Feb 26 at 12:36





+1: Very complete answer :)

– Dr. Manuel Kuehner
Feb 26 at 12:36




2




2





@Dr.ManuelKuehner By far not, but listing some common options :)

– TeXnician
Feb 26 at 12:37





@Dr.ManuelKuehner By far not, but listing some common options :)

– TeXnician
Feb 26 at 12:37











1














As already stated by others, verbatim does work for code (I use it for that purpose). The issue you see is that you usually format your code with tabs which verbatim is ignoring for some reason. So what I do is I put my code into verbatim select it and replace tabs with say 4 (or any number for that matter) of spaces (but just inside the selection).






share|improve this answer

























  • Are you sure that verbatim does not support tabs? In my case, it does.

    – JouleV
    Feb 26 at 16:16











  • i wrote a 80page script About the use of a finite element Analysis program that included a LOT of example Code with tabs. and i had to replace them all because else my Output would look like the one that the OP shared. this may depend on the tex Distribution however.

    – der bender
    Feb 26 at 16:18















1














As already stated by others, verbatim does work for code (I use it for that purpose). The issue you see is that you usually format your code with tabs which verbatim is ignoring for some reason. So what I do is I put my code into verbatim select it and replace tabs with say 4 (or any number for that matter) of spaces (but just inside the selection).






share|improve this answer

























  • Are you sure that verbatim does not support tabs? In my case, it does.

    – JouleV
    Feb 26 at 16:16











  • i wrote a 80page script About the use of a finite element Analysis program that included a LOT of example Code with tabs. and i had to replace them all because else my Output would look like the one that the OP shared. this may depend on the tex Distribution however.

    – der bender
    Feb 26 at 16:18













1












1








1







As already stated by others, verbatim does work for code (I use it for that purpose). The issue you see is that you usually format your code with tabs which verbatim is ignoring for some reason. So what I do is I put my code into verbatim select it and replace tabs with say 4 (or any number for that matter) of spaces (but just inside the selection).






share|improve this answer















As already stated by others, verbatim does work for code (I use it for that purpose). The issue you see is that you usually format your code with tabs which verbatim is ignoring for some reason. So what I do is I put my code into verbatim select it and replace tabs with say 4 (or any number for that matter) of spaces (but just inside the selection).







share|improve this answer














share|improve this answer



share|improve this answer








edited Feb 26 at 16:13









JouleV

6,46121750




6,46121750










answered Feb 26 at 16:09









der benderder bender

679




679












  • Are you sure that verbatim does not support tabs? In my case, it does.

    – JouleV
    Feb 26 at 16:16











  • i wrote a 80page script About the use of a finite element Analysis program that included a LOT of example Code with tabs. and i had to replace them all because else my Output would look like the one that the OP shared. this may depend on the tex Distribution however.

    – der bender
    Feb 26 at 16:18

















  • Are you sure that verbatim does not support tabs? In my case, it does.

    – JouleV
    Feb 26 at 16:16











  • i wrote a 80page script About the use of a finite element Analysis program that included a LOT of example Code with tabs. and i had to replace them all because else my Output would look like the one that the OP shared. this may depend on the tex Distribution however.

    – der bender
    Feb 26 at 16:18
















Are you sure that verbatim does not support tabs? In my case, it does.

– JouleV
Feb 26 at 16:16





Are you sure that verbatim does not support tabs? In my case, it does.

– JouleV
Feb 26 at 16:16













i wrote a 80page script About the use of a finite element Analysis program that included a LOT of example Code with tabs. and i had to replace them all because else my Output would look like the one that the OP shared. this may depend on the tex Distribution however.

– der bender
Feb 26 at 16:18





i wrote a 80page script About the use of a finite element Analysis program that included a LOT of example Code with tabs. and i had to replace them all because else my Output would look like the one that the OP shared. this may depend on the tex Distribution however.

– der bender
Feb 26 at 16:18

















draft saved

draft discarded
















































Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f476745%2fformat-code-pseudocode%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Isabella Eugénie Boyer Biographie | Références | Menu de navigationmodifiermodifier le codeComparator to Compute the Relative Value of a U.S. Dollar Amount – 1774 to Present.

Lioubotyn Sommaire Géographie | Histoire | Population | Notes et références | Liens externes | Menu de navigationlubotin.kharkov.uamodifier« Recensements et estimations de la population depuis 1897 »« Office des statistiques d'Ukraine : population au 1er janvier 2010, 2011 et 2012 »« Office des statistiques d'Ukraine : population au 1er janvier 2011, 2012 et 2013 »Informations officiellesCartes topographiquesCarte routièrem

Mpande kaSenzangakhona Biographie | Références | Menu de navigationmodifierMpande kaSenzangakhonavoir la liste des auteursm